@notis_ai/cli 0.2.30 → 0.2.32

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 (87) hide show
  1. package/README.md +15 -0
  2. package/config/notis_app_design_rules.json +22 -0
  3. package/dist/agent-hooks/notis-agent-hook.mjs +38244 -10823
  4. package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
  5. package/dist/base-skills/notis-cli/references/native-databases.md +1 -1
  6. package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
  7. package/dist/base-skills/notis-query/references/query.md +6 -4
  8. package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
  9. package/dist/base-skills/notis-spaces/SKILL.md +12 -4
  10. package/dist/base-skills/notis-spaces/references/architecture.md +4 -1
  11. package/dist/base-skills/notis-spaces/references/design.md +7 -1
  12. package/dist/base-skills/notis-spaces/references/fixtures.md +29 -2
  13. package/dist/base-skills/notis-spaces/references/reading.md +3 -1
  14. package/dist/base-skills/notis-spaces/references/release.md +3 -1
  15. package/dist/base-skills/notis-spaces/references/sdk.md +112 -33
  16. package/dist/base-skills/notis-spaces/references/troubleshooting.md +3 -0
  17. package/dist/base-skills/notis-spaces/references/views.md +20 -0
  18. package/dist/sdk/src/hooks/useNativeDocuments.ts +50 -12
  19. package/dist/sdk/src/index.ts +1 -1
  20. package/dist/sdk/src/space.ts +3 -1
  21. package/dist/sdk/src/tailwind.ts +53 -3
  22. package/dist/sdk/src/ui/icons.tsx +18 -1
  23. package/dist/sdk/src/words/types.ts +28 -0
  24. package/dist/skill-sync/index.js +10 -90
  25. package/dist/skill-sync-worker.mjs +50 -93
  26. package/dist/space-harness/host.js +155 -82
  27. package/dist/space-sdk/dist/chunk-I4Z4UFGB.js +3 -0
  28. package/dist/space-sdk/dist/index.js +2 -2
  29. package/dist/space-sdk/dist/ui.js +12 -12
  30. package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +23 -0
  31. package/dist/space-sdk/src/index.d.ts +1 -1
  32. package/dist/space-sdk/src/space.ts +3 -1
  33. package/dist/space-sdk/src/tailwind-candidates.d.ts +315 -2
  34. package/dist/space-sdk/src/tailwind.ts +53 -3
  35. package/dist/space-sdk/src/ui/blocks/DataTable.d.ts +19 -4
  36. package/dist/space-sdk/src/ui/blocks/Meter.d.ts +12 -3
  37. package/dist/space-sdk/src/ui/blocks/Tabs.d.ts +7 -1
  38. package/dist/space-sdk/src/ui/blocks/blocks.d.ts +18 -0
  39. package/dist/space-sdk/src/ui/blocks/index.d.ts +3 -3
  40. package/dist/space-sdk/src/ui/charts/CalendarHeatmap.d.ts +69 -0
  41. package/dist/space-sdk/src/ui/charts/Chart.d.ts +18 -3
  42. package/dist/space-sdk/src/ui/charts/chartData.d.ts +19 -0
  43. package/dist/space-sdk/src/ui/charts/heatmapData.d.ts +81 -0
  44. package/dist/space-sdk/src/ui/icons.d.ts +6 -0
  45. package/dist/space-sdk/src/ui/index.d.ts +5 -3
  46. package/dist/space-sdk/src/ui/list/ListReader.d.ts +8 -0
  47. package/dist/space-sdk/src/ui/list/Row.d.ts +11 -1
  48. package/dist/space-sdk/src/ui/period/dateFormat.d.ts +2 -0
  49. package/dist/space-sdk/src/ui/period/dateWords.d.ts +9 -0
  50. package/dist/space-sdk/src/ui/period/periods.d.ts +15 -2
  51. package/dist/space-sdk/src/words/types.ts +28 -0
  52. package/dist/view-renderer/dist/host.js +224 -151
  53. package/dist/view-renderer/src/dom.js +3 -2
  54. package/dist/view-renderer/src/errors.js +9 -0
  55. package/dist/view-renderer/src/host.tsx +12 -5
  56. package/dist/view-renderer/src/remote-broker.js +3 -1
  57. package/dist/view-renderer/src/renderer.js +63 -16
  58. package/dist/view-renderer/src/skeleton.js +70 -18
  59. package/package.json +5 -4
  60. package/skills/notis-query/cli.md +3 -0
  61. package/skills/notis-spaces/cli.md +14 -0
  62. package/src/command-specs/spaces.js +138 -15
  63. package/src/command-specs/tools.js +3 -0
  64. package/src/runtime/api-hosts.generated.js +35 -0
  65. package/src/runtime/api-hosts.js +27 -10
  66. package/src/runtime/app-boundary-validator.js +248 -3
  67. package/src/runtime/app-data-literals.js +32 -23
  68. package/src/runtime/app-platform.js +68 -24
  69. package/src/runtime/http-agent.js +53 -0
  70. package/src/runtime/native-record-files.js +11 -0
  71. package/src/runtime/oauth.js +2 -1
  72. package/src/runtime/skill-sync/cloud-client.ts +0 -10
  73. package/src/runtime/skill-sync/index.ts +13 -15
  74. package/src/runtime/skill-sync/local-scanner.ts +0 -67
  75. package/src/runtime/skill-sync/types.ts +1 -0
  76. package/src/runtime/skill-sync/write-cloud-skill.ts +7 -23
  77. package/src/runtime/space-dependencies.js +66 -0
  78. package/src/runtime/space-fixture-broker.js +23 -8
  79. package/src/runtime/space-platform.js +47 -3
  80. package/src/runtime/space-source.js +10 -1
  81. package/src/runtime/space-test-server.js +124 -6
  82. package/src/runtime/space-verification.js +103 -43
  83. package/src/runtime/space-view-manifest.js +38 -5
  84. package/src/runtime/transport.js +19 -4
  85. package/src/runtime/view-render.js +4 -1
  86. package/template/tailwind.config.ts +2 -35
  87. package/dist/space-sdk/dist/chunk-6GJ2BS7B.js +0 -3
@@ -1,5 +1,5 @@
1
1
  /** Pure fixture adapter for the exact CLI/service renderer; no network client. */
2
- import { createSpaceFixtureEngine, spaceHarnessSnapshot } from './space-test-server.js';
2
+ import { createSpaceFixtureEngine, selectedFixtureContext, spaceHarnessSnapshot } from './space-test-server.js';
3
3
  import { usageError } from './errors.js';
4
4
 
5
5
  const object = value => value && typeof value === 'object' && !Array.isArray(value);
@@ -21,25 +21,38 @@ export function fixtureSkeletonParams(release) {
21
21
  }
22
22
 
23
23
  /**
24
- * `audience: 'public'` draws the view as the public sees it: the editor's descriptor with View as the public on, so
24
+ * The fixture contexts verify opens the view in, in order: `[{ name, params, open }]` (`open`: the params open a list
25
+ * item through ListReader's default `open` param). Unreadable fixtures give none; verify reports them on its own.
26
+ */
27
+ export function fixtureContexts(release) {
28
+ let engine;
29
+ try { engine = createSpaceFixtureEngine(release); } catch { return []; }
30
+ return engine.contexts.map(({ name, context }) => ({ name, params: structuredClone(context.params || {}),
31
+ open: typeof context.params?.open === 'string' && context.params.open.length > 0 }));
32
+ }
33
+
34
+ /**
35
+ * `context` names the fixture context to open the view with (default: the first). `audience: 'public'` draws the view as the public sees it: the editor's descriptor with View as the public on, so
25
36
  * the page applies the public floors itself (no editor-only lists, actions, params or columns), as in the Portal.
26
37
  */
27
38
  export function createSpaceFixtureBroker({ release, capabilities, width, outputs = ['markdown', 'screenshot'],
28
- authorizationMode = 'authorize_missing', unavailableActions = [], onFailure, params: paramsOverride, audience = 'editor' }) {
39
+ authorizationMode = 'authorize_missing', unavailableActions = [], onFailure, params: paramsOverride, audience = 'editor', context: contextName }) {
29
40
  const engine = createSpaceFixtureEngine(release);
30
- const frozen = spaceHarnessSnapshot(release, capabilities, engine, { authorizationMode, unavailableActions });
41
+ const selected = selectedFixtureContext(engine, contextName).context;
42
+ const frozen = spaceHarnessSnapshot(release, capabilities, engine, { authorizationMode, unavailableActions, context: contextName });
31
43
  if (audience === 'public') frozen.descriptor.space.viewAs = 'public';
32
44
  const calls = [];
33
45
  // Skeleton capture may open the view with other params (a tab), on top of the fixture's own.
34
- const params = structuredClone({ ...(engine.context.params || {}), ...(paramsOverride || {}) });
46
+ const params = structuredClone({ ...(selected.params || {}), ...(paramsOverride || {}) });
35
47
  // The fixture's own "now" pins the browser clock, so a view that asks for the
36
48
  // last hour sends the exact inputs its fixtures recorded.
37
- const now = engine.context.now;
49
+ const now = selected.now;
38
50
  const fixedClock = typeof now === 'string' && Number.isFinite(Date.parse(now)) ? { fixed_clock: now } : {};
39
51
  const value = { ...frozen, url: `https://app.notis.ai/verification/${encodeURIComponent(release.manifest.local_key)}`,
40
52
  view: { space_id: frozen.descriptor.resource.id, name: release.manifest.name, revision: 1 },
41
- locale: engine.context.locale === 'fr' ? 'fr' : 'en', params,
42
- markdownExport: release.manifest.markdown?.export_name || null, render_options: { outputs, width }, ...fixedClock };
53
+ locale: selected.locale === 'fr' ? 'fr' : 'en', params,
54
+ markdownExport: release.manifest.markdown?.export_name || null, render_options: { outputs, width }, ...fixedClock,
55
+ asset_images: [...engine.imageUrls] };
43
56
  return {
44
57
  fixtureDigest: engine.digest,
45
58
  calls,
@@ -80,6 +93,8 @@ export function createSpaceFixtureBroker({ release, capabilities, width, outputs
80
93
  } else if (request?.operation === 'document_body' && exact(request, ['operation', 'record_key', 'binding', 'read_action'])) {
81
94
  if (frozen.descriptor.space.actions[request.read_action]?.readOnly !== true) throw usageError('This document read action is unavailable.');
82
95
  result = engine.executeBody({ operation: 'read', recordKey: request.record_key, binding: request.binding, readAction: request.read_action });
96
+ } else if (request?.operation === 'asset' && exact(request, ['operation', 'url', 'kind']) && request.kind === 'image') {
97
+ result = engine.executeImage(request.url);
83
98
  } else if (['record', 'html', 'report'].includes(request?.operation) && exact(request, ['operation', 'record_key'])) {
84
99
  result = engine.executeRecordView(request.operation, request.record_key);
85
100
  } else {
@@ -8,6 +8,7 @@ import { viewManifestFields } from './space-view-manifest.js';
8
8
  import { editorsOnlySummary, manifestActions, manifestResources } from './space-audience.js';
9
9
  import { usageError } from './errors.js';
10
10
  import { assertSourceRoot } from './source-root.js';
11
+ import { ensureSpaceDependencies } from './space-dependencies.js';
11
12
 
12
13
  const SPACE_ICON = /^(phosphor:[a-z0-9]+(-[a-z0-9]+)*|https:\/\/\S{1,2000})$/;
13
14
 
@@ -102,9 +103,12 @@ function finalizeSelectedArtifact(projectDir) {
102
103
  * dependencies; it is not another authoring project or dependency installation.
103
104
  * The existing pinned freeze/receipt code owns all staging writes and cleanup.
104
105
  */
105
- export async function buildSpaceRelease(projectDir, selectedKey, { stdio = 'inherit', refreshSdk = true, runBuild, designBar = 'enforce', designLog = null } = {}) {
106
+ export async function buildSpaceRelease(projectDir, selectedKey, { stdio = 'inherit', refreshSdk = true, runBuild, designBar = 'enforce', designLog = null,
107
+ installDependencies = false, installLog } = {}) {
106
108
  projectDir = assertSourceRoot(projectDir);
107
109
  if (refreshSdk) syncSpaceSdk(projectDir);
110
+ // After the SDK sync, so the install follows the lock file that sync keeps in step with the SDK.
111
+ const installed = installDependencies ? ensureSpaceDependencies(projectDir, { log: installLog }) : null;
108
112
  const selection = await loadSelectedSpace(projectDir, selectedKey);
109
113
  const sourceFiles = collectSelectedSpaceSource(projectDir, selection);
110
114
  const sourceHash = appFilesDigest(sourceFiles);
@@ -122,7 +126,8 @@ export async function buildSpaceRelease(projectDir, selectedKey, { stdio = 'inhe
122
126
  if (sourceHash !== appFilesDigest(collectSelectedSpaceSource(projectDir, current))) throw usageError('This Space source changed during the selected build. Build again.');
123
127
  release = prepareAppRelease(staging.projectDir);
124
128
  const close = release.close;
125
- return { ...release, selectedKey, sourceHash, fixturePath: selection.fixturePath, close() { try { close(); } finally { staging.close(); } } };
129
+ return { ...release, selectedKey, sourceHash, fixturePath: selection.fixturePath, ...(installed ? { installed } : {}),
130
+ close() { try { close(); } finally { staging.close(); } } };
126
131
  } catch (error) {
127
132
  try { release?.close(); } finally { staging.close(); }
128
133
  throw error;
@@ -133,10 +138,49 @@ export async function buildSpaceArtifact(projectDir, selectedKey, options) {
133
138
  const release = await buildSpaceRelease(projectDir, selectedKey, options);
134
139
  try {
135
140
  const receiptPath = saveSelectedBuild(projectDir, selectedKey, release);
136
- return { manifest: release.manifest, receiptPath, sourceHash: release.sourceHash };
141
+ return { manifest: release.manifest, receiptPath, sourceHash: release.sourceHash, ...(release.installed ? { installed_dependencies: release.installed } : {}) };
137
142
  } finally { release.close(); }
138
143
  }
139
144
 
145
+ const SQL_READ_HEADER = /^\/\* notis-postgres-read-v\d+ \*\/\n/;
146
+
147
+ /** Declared actions whose query starts with a SQL read header line (the server's requests_read). */
148
+ export function sqlReadActions(manifest) {
149
+ return Object.fromEntries(Object.entries(manifest?.actions || {}).filter(([, template]) => {
150
+ let query = template?.arguments?.query;
151
+ if (query && typeof query === 'object') query = query.$literal ?? query.$sql?.parts?.[0];
152
+ return typeof query === 'string' && SQL_READ_HEADER.test(query);
153
+ }));
154
+ }
155
+
156
+ /**
157
+ * Check every declared SQL read with the server's compiler before verification. A compiled read
158
+ * passes unchanged; a header line and plain SELECT joins the release compiled, in memory only, so
159
+ * the source keeps the plain query and each build compiles it to the same bytes. A refused read
160
+ * stops here with the compiler's reason.
161
+ */
162
+ export async function compileSpaceSqlReads(release, call) {
163
+ const actions = sqlReadActions(release.manifest);
164
+ if (!Object.keys(actions).length) return [];
165
+ let response;
166
+ try { response = await call('sql-reads', { actions }); }
167
+ catch (error) {
168
+ // A server from before this check: compiled reads go on to its own verification.
169
+ if (error?.httpStatus !== 404) throw error;
170
+ const plain = Object.values(actions).filter(template => !JSON.stringify(template.arguments.query).includes('/* guarded-relations:'));
171
+ if (!plain.length) return [];
172
+ throw usageError('This Notis server cannot compile SQL reads yet. Write each read compiled, or verify against a newer server.');
173
+ }
174
+ const compiled = response.payload?.actions || {};
175
+ const names = Object.keys(compiled).filter(name => Object.hasOwn(actions, name));
176
+ if (!names.length) return [];
177
+ const manifest = { ...release.manifest, actions: { ...release.manifest.actions } };
178
+ for (const name of names) manifest.actions[name] = compiled[name];
179
+ release.manifest = manifest;
180
+ release.files = { ...release.files, 'manifest.json': Buffer.from(JSON.stringify(manifest, null, 2), 'utf8').toString('base64') };
181
+ return names;
182
+ }
183
+
140
184
  export async function prepareSpaceRelease(projectDir, selectedKey) {
141
185
  const selection = await loadSelectedSpace(projectDir, selectedKey);
142
186
  const source = collectSelectedSpaceSource(projectDir, selection);
@@ -4,6 +4,7 @@ import { realpathSync } from 'node:fs';
4
4
  import { dirname, extname, join, relative, resolve, sep } from 'node:path';
5
5
  import { collectSourceFiles, loadAppConfig } from './app-platform.js';
6
6
  import { usageError } from './errors.js';
7
+ import { fixtureImageEntries } from './space-test-server.js';
7
8
  import { VIEW_DEFINITION_FIELDS, viewManifestFields } from './space-view-manifest.js';
8
9
  import { editorOnlyColumns, editorsOnlyFlag, withoutMarker } from './space-audience.js';
9
10
 
@@ -308,7 +309,15 @@ export function collectSelectedSpaceSource(projectDir, selection, { buildInputs
308
309
  if (selection.entry) add(selection.entry);
309
310
  if (selection.layout) add(selection.layout);
310
311
  if (selection.markdown) add(selection.markdown);
311
- if (selection.fixturePath) add(selection.fixturePath);
312
+ if (selection.fixturePath) {
313
+ add(selection.fixturePath);
314
+ // The image files the fixtures show travel with them; verify reports a bad entry on its own.
315
+ let fixtures;
316
+ try { fixtures = JSON.parse(Buffer.from(files[selection.fixturePath], 'base64').toString('utf8')); } catch { fixtures = null; }
317
+ let images = [];
318
+ try { images = fixtureImageEntries(fixtures, selection.fixturePath); } catch { /* Reported by verify. */ }
319
+ for (const { path } of images) if (Object.hasOwn(files, path)) try { add(path); } catch { /* Verify names the file it cannot use. */ }
320
+ }
312
321
  for (const include of selection.definition.sourceIncludes || []) {
313
322
  const path = selection.resolveDefinitionPath(include);
314
323
  const matches = Object.keys(files).filter(name => name === path || name.startsWith(path + '/'));
@@ -2,12 +2,12 @@
2
2
  import { createHash } from 'node:crypto';
3
3
  import { readFileSync } from 'node:fs';
4
4
  import { createServer } from 'node:http';
5
- import { dirname, join, resolve } from 'node:path';
5
+ import { dirname, extname, join, posix, resolve } from 'node:path';
6
6
  import { isDeepStrictEqual } from 'node:util';
7
7
  import { fileURLToPath } from 'node:url';
8
8
  import Ajv2020 from 'ajv/dist/2020.js';
9
9
  import addFormats from 'ajv-formats';
10
- import { appFilesDigest } from './app-platform.js';
10
+ import { appFilesDigest, VERIFY_CONTEXT_NAME } from './app-platform.js';
11
11
  import { usageError } from './errors.js';
12
12
 
13
13
  const ROOT=resolve(dirname(fileURLToPath(import.meta.url)),'../..');
@@ -58,6 +58,102 @@ function recordViewExample(operation,key) {
58
58
  }[operation];
59
59
  return JSON.stringify({operation,record_key:key,result});
60
60
  }
61
+ const FIXTURE_CONTEXTS_MAX=4;
62
+ /**
63
+ * View params a fixture opens the view with: a flat object, as a link carries them. Numbers and true or false are
64
+ * kept (the host passes every param as text, as it always did); nested values are refused.
65
+ */
66
+ function checkContextFields(value,where) {
67
+ if(value.params!==undefined && (!object(value.params) || Object.values(value.params).some(item=>!['string','number','boolean'].includes(typeof item)))) {
68
+ throw usageError(`${where} params must be an object of text, number or true/false values, as a link carries them (for example {"period": "week"}).`);
69
+ }
70
+ if(value.now!==undefined && (typeof value.now!=='string' || !Number.isFinite(Date.parse(value.now)))) {
71
+ throw usageError(`${where} now must be a date string, such as "2026-03-01T09:00:00Z".`);
72
+ }
73
+ }
74
+ /**
75
+ * The states verify opens the view in: `contexts` (1 to 4 named ones, each with optional params, now and locale), or
76
+ * the one `context`, named default. Each entry keeps the object the view receives as its runtime context.
77
+ * `context.views`, the further params the Spaces review deck draws (portal/scripts/spaces-boundary), are states too:
78
+ * the first 3 that open another link than the context (key order, text or number, and a declared default do not
79
+ * count) follow default, each named view-<place in the list>, with the context's now and locale. The deck draws them all.
80
+ */
81
+ function fixtureContexts(fixtures,declared={}) {
82
+ if(fixtures.contexts===undefined) {
83
+ const value=fixtures.context || {};
84
+ checkContextFields(value,'The fixture context');
85
+ if(value.views===undefined) return [{name:'default',context:value}];
86
+ if(!Array.isArray(value.views) || value.views.some(item=>!object(item))) {
87
+ throw usageError('The fixture context views must be a list of view params, such as [{"period": "week"}].');
88
+ }
89
+ const {views,...base}=value;
90
+ // One link is one view, as the deck reads it: a declared default is left out of the link and 10 is "10".
91
+ const link=params=>JSON.stringify(Object.entries(params || {})
92
+ .filter(([name,item])=>!(object(declared[name]) && Object.hasOwn(declared[name],'default') && String(declared[name].default)===String(item)))
93
+ .map(([name,item])=>[name,String(item)]).sort(([a],[b])=>a<b ? -1 : a>b ? 1 : 0));
94
+ const seen=new Set([link(base.params)]),extra=[];
95
+ views.forEach((params,index)=>{
96
+ checkContextFields({params},`The fixture context view ${index+1}`);
97
+ if(seen.has(link(params)) || extra.length>=FIXTURE_CONTEXTS_MAX-1) return;
98
+ seen.add(link(params));
99
+ extra.push({name:`view-${index+1}`,context:{...base,params}});
100
+ });
101
+ return [{name:'default',context:base},...extra];
102
+ }
103
+ if(fixtures.context!==undefined) throw usageError('Verification fixtures declare either context or contexts, not both. Move context into contexts as one named entry.');
104
+ const list=fixtures.contexts;
105
+ if(!Array.isArray(list) || !list.length || list.length>FIXTURE_CONTEXTS_MAX) throw usageError(`Declare contexts as a list of 1 to ${FIXTURE_CONTEXTS_MAX} named contexts.`);
106
+ const names=new Set();
107
+ return list.map((value,index)=>{
108
+ const where=`Fixture context ${index+1}`;
109
+ if(!object(value) || Object.keys(value).some(key=>!['name','params','now','locale'].includes(key))) {
110
+ throw usageError(`${where} takes only name, params, now and locale.`);
111
+ }
112
+ if(typeof value.name!=='string' || !VERIFY_CONTEXT_NAME.test(value.name)) {
113
+ throw usageError(`${where} needs a name of lowercase letters, digits, "-" or "_" (at most 32), such as "this-week".`);
114
+ }
115
+ if(names.has(value.name)) throw usageError(`Two fixture contexts are named ${value.name}; give each its own name.`);
116
+ names.add(value.name);
117
+ checkContextFields(value,`Fixture context ${value.name}`);
118
+ const {name,...context}=value;
119
+ return {name,context};
120
+ });
121
+ }
122
+
123
+ // Fixture images: a URL the fixture rows hold (a photo, a cover) shows an image file kept next to the fixtures.
124
+ export const FIXTURE_IMAGES_MAX=32;
125
+ export const FIXTURE_IMAGE_BYTES_MAX=2*1024*1024;
126
+ // All of them together stay under what one render may load (32 MB, view-renderer).
127
+ export const FIXTURE_IMAGES_TOTAL_BYTES_MAX=16*1024*1024;
128
+ const FIXTURE_IMAGE_TYPES={'.png':'image/png','.jpg':'image/jpeg','.jpeg':'image/jpeg','.webp':'image/webp','.gif':'image/gif','.avif':'image/avif'};
129
+
130
+ /**
131
+ * `images` of a fixture file: `{ "<https URL a row holds>": "<image file, relative to the fixture file>" }`, as
132
+ * `[{url, path, type}]` with `path` relative to the Space folder. Throws on anything else.
133
+ */
134
+ export function fixtureImageEntries(fixtures,fixturePath) {
135
+ const images=fixtures?.images;
136
+ if(images===undefined) return [];
137
+ const where=fixturePath ? ` in ${fixturePath}` : '';
138
+ if(!object(images) || Object.keys(images).length>FIXTURE_IMAGES_MAX) {
139
+ throw usageError(`Declare fixture images${where} as an object of at most ${FIXTURE_IMAGES_MAX} entries: {"https://example.com/photo.jpg": "./photos/photo.jpg"}.`);
140
+ }
141
+ const base=posix.dirname(fixturePath || 'fixtures.json');
142
+ return Object.entries(images).map(([url,file])=>{
143
+ let parsed;
144
+ try { parsed=new URL(url); } catch {}
145
+ if(!parsed || parsed.protocol!=='https:' || parsed.username || parsed.password || parsed.hash || parsed.href!==url) {
146
+ throw usageError(`Fixture image ${JSON.stringify(url)}${where} must be an https URL, written exactly as the fixture rows hold it.`);
147
+ }
148
+ const type=typeof file==='string' ? FIXTURE_IMAGE_TYPES[extname(file).toLowerCase()] : undefined;
149
+ const path=typeof file==='string' ? posix.normalize(posix.join(base,file)) : '';
150
+ if(!type || !path || posix.isAbsolute(file) || file.split(/[\\/]/).includes('..')) {
151
+ throw usageError(`Fixture image ${JSON.stringify(url)}${where} must name a .png, .jpg, .webp, .gif or .avif file in the fixture file's folder or below it.`);
152
+ }
153
+ return {url,path,type};
154
+ });
155
+ }
156
+
61
157
  const VIEWER_READS={list_databases:'databases',get_database:'databases',query_database:'databases',list_skills:'skills',get_skill:'skills'};
62
158
 
63
159
  /**
@@ -85,8 +181,18 @@ export function createSpaceFixtureEngine(release) {
85
181
  try { fixtures=JSON.parse(Buffer.from(encoded,'base64').toString('utf8')); }
86
182
  catch { throw usageError('Verification fixtures must be finite JSON objects.'); }
87
183
  }
88
- if(!object(fixtures) || Object.keys(fixtures).some(key=>!['actions','context','documentBodies','viewerReads','shown','recordViews'].includes(key)) || !object(fixtures.actions)
184
+ if(!object(fixtures) || Object.keys(fixtures).some(key=>!['actions','context','contexts','documentBodies','viewerReads','shown','recordViews','images'].includes(key)) || !object(fixtures.actions)
89
185
  || (fixtures.context!==undefined && !object(fixtures.context))) throw usageError('Verification fixtures declare actions and optional synthetic context.');
186
+ const contexts=fixtureContexts(fixtures,release.manifest.params || {});
187
+ const images=new Map(fixtureImageEntries(fixtures,release.fixturePath).map(entry=>{
188
+ const encoded=release.sourceFiles[entry.path];
189
+ if(typeof encoded!=='string') throw usageError(`Fixture image ${entry.path} for ${entry.url} is missing from the Space folder.`);
190
+ if(Buffer.byteLength(encoded,'base64')>FIXTURE_IMAGE_BYTES_MAX) throw usageError(`Fixture image ${entry.path} is larger than 2 MB; use a smaller picture.`);
191
+ return [entry.url,{mime_type:entry.type,data_base64:encoded}];
192
+ }));
193
+ if([...images.values()].reduce((total,image)=>total+Buffer.byteLength(image.data_base64,'base64'),0)>FIXTURE_IMAGES_TOTAL_BYTES_MAX) {
194
+ throw usageError(`Fixture images${release.fixturePath ? ` in ${release.fixturePath}` : ''} add up to more than 16 MB; use smaller pictures.`);
195
+ }
90
196
  // Viewer reads have no grant: fixtures stand in for what a signed-in viewer could open.
91
197
  const declaredReads=release.manifest.viewer_reads || [];
92
198
  // V4: a declared list is served from fixtures per exact params, like a signed-in Editor's read.
@@ -202,7 +308,13 @@ export function createSpaceFixtureEngine(release) {
202
308
  if(entry.operation==='html' && value.title!==undefined && value.title!==null && typeof value.title!=='string') throw usageError('HTML fixtures contain a record key, HTML and an optional title.');
203
309
  if(entry.operation==='report' && (typeof value.source!=='string' || typeof value.export_name!=='string')) throw usageError('Report fixtures contain an explicit readonly source and export.');
204
310
  }
205
- return { context:fixtures.context || {}, digest:createHash('sha256').update(JSON.stringify(fixtures)).digest('hex'),
311
+ return { context:fixtures.context || {}, contexts, digest:[...images.values()].reduce((hash,image)=>hash.update(image.data_base64),createHash('sha256').update(JSON.stringify(fixtures))).digest('hex'),
312
+ imageUrls:[...images.keys()],
313
+ executeImage(url) {
314
+ const image=images.get(url);
315
+ if(!image) throw usageError(`The view shows the image ${url}, which its fixtures do not provide. Add it to images in ${release.fixturePath || 'its fixtures'}.`);
316
+ return {...image};
317
+ },
206
318
  executeRecordView(operation,key) {
207
319
  const match=recordViews.find(value=>value.operation===operation && value.record_key===key);
208
320
  if(!match) {
@@ -241,7 +353,13 @@ export function createSpaceFixtureEngine(release) {
241
353
  } };
242
354
  }
243
355
 
244
- export function spaceHarnessSnapshot(release,capabilities,engine,{authorizationMode='authorize_missing',unavailableActions=[]}={}) {
356
+ /** The fixture context a render opens with: the named one of `contexts`, else the first (the only `context`). */
357
+ export function selectedFixtureContext(engine,name) {
358
+ const list=engine.contexts || [{name:'default',context:engine.context || {}}];
359
+ return (name===undefined ? list[0] : list.find(item=>item.name===name)) || (()=>{ throw usageError(`The fixtures have no context named ${JSON.stringify(String(name))}.`); })();
360
+ }
361
+
362
+ export function spaceHarnessSnapshot(release,capabilities,engine,{authorizationMode='authorize_missing',unavailableActions=[],context:contextName}={}) {
245
363
  if(release.manifest.kind!=='presentation') throw usageError('Containers do not have an executable preview.');
246
364
  const manifest=release.manifest;
247
365
  const names=Object.keys(manifest.actions || {}).sort();
@@ -288,7 +406,7 @@ export function spaceHarnessSnapshot(release,capabilities,engine,{authorizationM
288
406
  ...(viewerReads.length?{viewerReads}:{}),...viewDeclarations(manifest),
289
407
  // A local verification renders as an Editor, with the editor-only summary the server gives Editors.
290
408
  audience:'editor',...(manifest.editors_only?{editorsOnly:editorsOnlyDescriptor(manifest.editors_only)}:{})},
291
- app:{id:identity,name:manifest.name},route:{slug:'view',path:'/',name:manifest.name},context:engine.context} };
409
+ app:{id:identity,name:manifest.name},route:{slug:'view',path:'/',name:manifest.name},context:selectedFixtureContext(engine,contextName).context} };
292
410
  }
293
411
 
294
412
  /** Existing CLI theme only; the legacy executable/JWT HTML is never served. */
@@ -2,8 +2,8 @@
2
2
  import { createHash } from 'node:crypto';
3
3
  import { existsSync, readFileSync } from 'node:fs';
4
4
  import { fileURLToPath } from 'node:url';
5
- import { appFilesDigest } from './app-platform.js';
6
- import { createSpaceFixtureBroker, fixtureSkeletonParams } from './space-fixture-broker.js';
5
+ import { appFilesDigest, VERIFY_LOCALES, VERIFY_WIDTHS } from './app-platform.js';
6
+ import { createSpaceFixtureBroker, fixtureContexts, fixtureSkeletonParams } from './space-fixture-broker.js';
7
7
 
8
8
  // Kept for the standalone legacy worker's lifecycle tests while that diagnostic
9
9
  // entrypoint is retired. The primary verifier below never starts that worker.
@@ -43,7 +43,16 @@ async function acquire(signal) {
43
43
  }
44
44
  function releaseSlot() { const next = waiting.shift(); if (next) next.accept(); else active--; }
45
45
 
46
- /** Initial deployment checks the exact captured bytes at both product widths. */
46
+ const LANGUAGES = { en: 'English', fr: 'French' };
47
+ /** Where one render was taken, for messages: "390 px in French" and, with several contexts, the context's name. */
48
+ const placeOf = ({ width, locale, context }) => `${width} px in ${LANGUAGES[locale]}${context ? `, context ${context}` : ''}`;
49
+ // The reads a reader's loading pass holds: the opened item's record and body; the list around it answers.
50
+ const READER_HOLDS = ['record', 'document_body', 'html', 'report'];
51
+
52
+ /**
53
+ * Initial deployment checks the exact captured bytes at both product widths, in English and French, once per fixture
54
+ * context (`contexts` in the fixtures, else the one `context`).
55
+ */
47
56
  export async function verifySpaceRelease(release, { capabilities, timeoutMs = 45_000, signal, loadRenderer = loadSpaceVerificationRenderer,
48
57
  authorizationMode = 'authorize_missing', unavailableActions = [] } = {}) {
49
58
  const diagnostic = { schema: 'notis-space-render/v1', local_key: release.manifest.local_key,
@@ -54,13 +63,18 @@ export async function verifySpaceRelease(release, { capabilities, timeoutMs = 45
54
63
  if (signal?.aborted) return { ...diagnostic, status: 'failed', errors: [{ phase: 'browser', message: 'Verification cancelled.' }] };
55
64
  if (release.manifest.kind === 'container') return { ...diagnostic, status: 'not_applicable_container' };
56
65
  let pool, held = false, rendererDigest;
57
- const brokers = [390, 1440].map(width => ({ width, broker: null, stop: new AbortController(), timer: null }));
66
+ // Several contexts name their images and messages; one context keeps the plain names.
67
+ const contexts = fixtureContexts(release), named = contexts.length > 1;
68
+ const brokers = [];
69
+ for (const { name } of contexts.length ? contexts : [{ name: undefined }]) for (const locale of VERIFY_LOCALES) for (const width of VERIFY_WIDTHS) {
70
+ brokers.push({ width, locale, contextName: name, ...(named ? { context: name } : {}), broker: null, stop: new AbortController(), timer: null });
71
+ }
58
72
  try {
59
73
  // Validate fixture authority before opening a browser or acquiring a slot.
60
74
  // A failed fixture read already fails the check, and the view usually waits on it until the timeout: the
61
75
  // render stops shortly after, once the reads the view sends together have had their say.
62
76
  for (const item of brokers) item.broker = createSpaceFixtureBroker({ release, capabilities, width: item.width,
63
- authorizationMode, unavailableActions, onFailure: () => {
77
+ authorizationMode, unavailableActions, context: item.contextName, onFailure: () => {
64
78
  item.timer ??= setTimeout(() => item.stop.abort(), FIXTURE_FAILURE_GRACE_MS);
65
79
  } });
66
80
  await acquire(signal); held = true;
@@ -70,55 +84,70 @@ export async function verifySpaceRelease(release, { capabilities, timeoutMs = 45
70
84
  // waits; a view still loading after the bounded wait keeps a screenshot of what it showed, and says so.
71
85
  const readyTimeoutMs = readyWait(timeoutMs);
72
86
  const screenshots = [];
73
- const observations = await Promise.allSettled(brokers.map(async ({ width, broker, stop }) => {
74
- const cancel = signal ? AbortSignal.any([signal, stop.signal]) : stop.signal;
75
- const result = await library.renderView({ broker, pool, outputs: ['markdown', 'screenshot'], width, timeoutMs, signal: cancel,
76
- ...(readyTimeoutMs ? { readyTimeoutMs } : {}) });
77
- const blocked = result.blocked_calls || [];
78
- const png = Buffer.from(result.screenshot.data_base64, 'base64');
79
- screenshots.push({ width, png });
80
- return { width, mounted: true, status: blocked.length ? 'failed' : 'passed', loaded: true,
81
- markdown_sha256: createHash('sha256').update(result.markdown).digest('hex'),
82
- screenshot_sha256: sha256(png),
83
- screenshot_width: result.screenshot.width, screenshot_height: result.screenshot.height,
84
- rendered_at: result.rendered_at, blocked_calls: blocked };
85
- }));
87
+ const tag = ({ width, locale, context }) => ({ width, locale, ...(context ? { context } : {}) });
88
+ const observations = [];
89
+ // Both widths of one context and locale render together: the pool holds two renders at a time.
90
+ for (let index = 0; index < brokers.length; index += VERIFY_WIDTHS.length) {
91
+ observations.push(...await Promise.allSettled(brokers.slice(index, index + VERIFY_WIDTHS.length).map(async (item) => {
92
+ const { width, locale, broker, stop } = item;
93
+ const cancel = signal ? AbortSignal.any([signal, stop.signal]) : stop.signal;
94
+ const result = await library.renderView({ broker, pool, outputs: ['markdown', 'screenshot'], width, locale, timeoutMs, signal: cancel,
95
+ ...(readyTimeoutMs ? { readyTimeoutMs } : {}) });
96
+ const blocked = result.blocked_calls || [];
97
+ const png = Buffer.from(result.screenshot.data_base64, 'base64');
98
+ screenshots.push({ ...tag(item), png });
99
+ return { ...tag(item), mounted: true, status: blocked.length ? 'failed' : 'passed', loaded: true,
100
+ markdown_sha256: createHash('sha256').update(result.markdown).digest('hex'),
101
+ screenshot_sha256: sha256(png),
102
+ screenshot_width: result.screenshot.width, screenshot_height: result.screenshot.height,
103
+ rendered_at: result.rendered_at, blocked_calls: blocked };
104
+ })));
105
+ }
86
106
  const renders = observations.map((value, index) => {
87
107
  if (value.status === 'fulfilled') return value.value;
88
- const width = brokers[index].width, shot = value.reason?.code === 'render_not_ready' ? value.reason.screenshot : null;
108
+ const item = brokers[index], where = tag(item), place = placeOf(item);
109
+ const shot = value.reason?.code === 'render_not_ready' ? value.reason.screenshot : null;
89
110
  if (value.reason?.code === 'render_view_failed') {
90
- return { width, mounted: false, status: 'failed', error: 'render_view_failed', loaded: false,
91
- message: `At ${width} px the view's code failed before it showed anything${value.reason.reason ? `: ${value.reason.reason}` : '.'}` };
111
+ return { ...where, mounted: false, status: 'failed', error: 'render_view_failed', loaded: false,
112
+ message: `At ${place} the view's code failed before it showed anything${value.reason.reason ? `: ${value.reason.reason}` : '.'}` };
92
113
  }
93
- if (!shot?.data_base64) return { width, mounted: false, status: 'failed', error: value.reason?.code || 'render_failed' };
114
+ if (!shot?.data_base64) return { ...where, mounted: false, status: 'failed', error: value.reason?.code || 'render_failed',
115
+ ...(Array.isArray(value.reason?.blocked) && value.reason.blocked.length ? { blocked_calls: value.reason.blocked } : {}) };
94
116
  const png = Buffer.from(shot.data_base64, 'base64');
95
- screenshots.push({ width, png });
117
+ screenshots.push({ ...where, png });
96
118
  const mounted = value.reason.mounted === true;
97
119
  const seconds = value.reason.waitedSeconds || Math.round((readyTimeoutMs || 0) / 1000);
98
- return { width, mounted, status: 'failed', error: 'render_not_ready', loaded: false,
99
- message: mounted ? `At ${width} px the view had not finished loading its data after ${seconds} s.`
100
- : `At ${width} px the view had not shown anything after ${seconds} s.`,
120
+ return { ...where, mounted, status: 'failed', error: 'render_not_ready', loaded: false,
121
+ message: mounted ? `At ${place} the view had not finished loading its data after ${seconds} s.`
122
+ : `At ${place} the view had not shown anything after ${seconds} s.`,
101
123
  screenshot_sha256: sha256(png), screenshot_width: shot.width, screenshot_height: shot.height,
102
124
  blocked_calls: Array.isArray(value.reason.blocked) ? value.reason.blocked : [] };
103
125
  });
104
- screenshots.sort((left, right) => left.width - right.width);
105
- const runtimeCalls = brokers.flatMap(({ width, broker }) => broker.calls.map(call => ({ width, ...call })));
126
+ const order = item => brokers.findIndex(value => value.width === item.width && value.locale === item.locale && value.context === item.context);
127
+ screenshots.sort((left, right) => order(left) - order(right));
128
+ const runtimeCalls = brokers.flatMap(item => item.broker.calls.map(call => ({ ...tag(item), ...call })));
106
129
  const passed = renders.every(value => value.status === 'passed') && runtimeCalls.every(call => call.ok);
107
130
  // Each distinct fixture reason once (both widths usually hit the same one), ahead of the generic line.
108
131
  const fixtureErrors = [...new Map(runtimeCalls.filter(call => !call.ok && call.error)
109
132
  .map(call => [call.error, { phase: 'fixture', operation: call.operation,
110
133
  ...(call.recordKey ? { record_key: call.recordKey } : {}), ...(call.actionId ? { action_id: call.actionId } : {}),
111
134
  message: call.error }])).values()].slice(0, 10);
135
+ // An image URL the fixtures do not provide is named once, whatever width or language met it.
136
+ const images = [...new Set(renders.flatMap(value => (value.blocked_calls || []).map(call => call.image)).filter(Boolean))];
137
+ if (images.length) fixtureErrors.push({ phase: 'fixture', operation: 'asset',
138
+ message: `The view shows ${images.length === 1 ? 'an image' : `${images.length} images`} its fixtures do not provide (${images.slice(0, 3).join(', ')}${images.length > 3 ? ', ...' : ''}). `
139
+ + 'Add each URL to "images" in the fixtures, mapped to a picture file next to them: {"images": {"https://example.com/photo.jpg": "./photos/photo.jpg"}}.' });
112
140
  const notReady = renders.filter(value => value.error === 'render_not_ready' || value.error === 'render_view_failed')
113
- .map(value => ({ phase: 'renderer', width: value.width, message: value.message }));
141
+ .map(value => ({ phase: 'renderer', ...tag(value), message: value.message }));
114
142
  const result = { ...diagnostic, status: passed ? 'passed' : 'failed', mounted: renders.every(value => value.mounted),
115
143
  fixture_digest: brokers[0].broker.fixtureDigest, renderer_digest: rendererDigest,
116
- render_count: renders.length, browser_count: 1, renders, runtimeCalls,
144
+ render_count: renders.length, browser_count: 1, ...(named ? { contexts: contexts.map(value => value.name) } : {}), renders, runtimeCalls,
117
145
  errors: passed ? [] : [...fixtureErrors, ...notReady, { phase: 'renderer', message: 'At least one width or read-only fixture failed verification.' }] };
118
146
  Object.defineProperty(result, 'screenshots', { value: screenshots, enumerable: false });
119
147
  // The skeleton is measured only from a view that rendered cleanly, with a renderer that can measure it.
120
148
  if (passed && typeof library.buildSkeletonDocument === 'function') {
121
- const capture = await captureSpaceSkeleton({ library, pool, release, capabilities, timeoutMs, signal, authorizationMode, unavailableActions });
149
+ const capture = await captureSpaceSkeleton({ library, pool, release, capabilities, timeoutMs, signal, authorizationMode, unavailableActions,
150
+ contexts, named });
122
151
  result.skeleton = capture.skeleton;
123
152
  Object.defineProperty(result, 'skeletonDocument', { value: capture.document, enumerable: false });
124
153
  Object.defineProperty(result, 'pendingScreenshots', { value: capture.screenshots, enumerable: false });
@@ -140,15 +169,19 @@ const READY_MARGIN_MS = 5_000;
140
169
  const readyWait = timeoutMs => (timeoutMs - READY_MARGIN_MS >= 1_000 ? timeoutMs - READY_MARGIN_MS : undefined);
141
170
 
142
171
  const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
143
- const captureFailure = (width, locale, error) => ({ check: 'capture_failed', severity: 'warning', width, locale,
172
+ const captureFailure = (width, locale, error, extra = {}) => ({ check: 'capture_failed', severity: 'warning', width, locale, ...extra,
144
173
  message: `The loading skeleton could not be measured: ${String(error?.code || error?.message || error).slice(0, 300)}` });
145
174
 
146
175
  /**
147
176
  * Loading skeleton capture, per width and locale: (1) pending with the view's fallback skeleton gives the region
148
177
  * boxes and landmarks, (2) final measures the bones inside those boxes, (3) pending again with the measured bones
149
178
  * injected is checked and screenshotted. Never throws: failures become warnings and status `failed`.
179
+ * The first fixture context is the opening view; `context.skeletonParams` and every other context add the regions they
180
+ * show. (4) A context whose params open a list item (`open`) is also drawn with the list answered and the item's record
181
+ * held: the reader's loading state, checked and screenshotted as `state: 'reader'`.
150
182
  */
151
- async function captureSpaceSkeleton({ library, pool, release, capabilities, timeoutMs, signal, authorizationMode, unavailableActions }) {
183
+ async function captureSpaceSkeleton({ library, pool, release, capabilities, timeoutMs, signal, authorizationMode, unavailableActions,
184
+ contexts = [], named = false }) {
152
185
  const findings = [], screenshots = [], combos = [];
153
186
  let failed = false, document = null;
154
187
  const widths = library.SKELETON_WIDTHS || [390, 1440], locales = library.SKELETON_LOCALES || ['en', 'fr'];
@@ -157,8 +190,10 @@ async function captureSpaceSkeleton({ library, pool, release, capabilities, time
157
190
  // view that is wholly editor-only does not exist for the public: it keeps the editors' skeleton.
158
191
  const marks = release.manifest.editors_only;
159
192
  const audience = marks && !marks.view ? 'public' : 'editor';
160
- const render = (width, options, params) => library.renderView({ broker: createSpaceFixtureBroker({ release, capabilities, width,
161
- outputs: ['markdown'], authorizationMode, unavailableActions, params, audience }), pool, outputs: ['markdown'], width, timeoutMs, signal, ...options });
193
+ const render = (width, options, params, context) => library.renderView({ broker: createSpaceFixtureBroker({ release, capabilities, width,
194
+ outputs: ['markdown'], authorizationMode, unavailableActions, params, audience, context }), pool, outputs: ['markdown'], width, timeoutMs, signal, ...options });
195
+ // The pending landmarks end a region's measurement at the next one below it (a section head under a KPI row).
196
+ const measuring = (regions, pending) => ({ measure: { regions, landmarks: pending?.landmarks || [] } });
162
197
  // Both widths of one locale run together: the pool holds two renders at a time.
163
198
  const each = async (step) => {
164
199
  for (const locale of locales) {
@@ -178,28 +213,30 @@ async function captureSpaceSkeleton({ library, pool, release, capabilities, time
178
213
  combo.regions = combo.first?.pending?.static ? [] : (combo.first?.pending?.regions || []);
179
214
  const valid = combo.regions.filter(region => region.valid);
180
215
  if (!valid.length) return;
181
- combo.final = (await render(combo.width, { measure: { regions: valid }, locale: combo.locale })).skeleton_measure;
216
+ combo.final = (await render(combo.width, { ...measuring(valid, combo.first.pending), locale: combo.locale })).skeleton_measure;
182
217
  });
183
218
  const measurements = {};
184
219
  for (const combo of combos) if (combo.final) (measurements[combo.width] ||= {})[combo.locale] = { regions: combo.final.regions };
185
220
  // Regions a view shows only under other params (a tab it can open on), declared in the fixtures as
186
- // context.skeletonParams: measured the same way and added beside the opening view's own regions. A failure here
187
- // is a warning and never drops the regions already measured.
188
- for (const params of fixtureSkeletonParams(release)) {
221
+ // context.skeletonParams, or in another fixture context: measured the same way and added beside the opening
222
+ // view's own regions. A failure here is a warning and never drops the regions already measured.
223
+ const extras = [...fixtureSkeletonParams(release).map(params => ({ params })),
224
+ ...contexts.slice(1).map(value => ({ context: value.name }))];
225
+ for (const { params, context } of extras) {
189
226
  for (const locale of locales) {
190
227
  const settled = await Promise.allSettled(widths.map(async (width) => {
191
- const pending = (await render(width, { pending: true, locale }, params))?.pending;
228
+ const pending = (await render(width, { pending: true, locale }, params, context))?.pending;
192
229
  const known = new Set((measurements[width]?.[locale]?.regions || []).map(region => region.key));
193
230
  const valid = pending?.static ? [] : (pending?.regions || []).filter(region => region.valid && !known.has(region.key));
194
231
  if (!valid.length) return;
195
- const final = (await render(width, { measure: { regions: valid }, locale }, params)).skeleton_measure;
232
+ const final = (await render(width, { ...measuring(valid, pending), locale }, params, context)).skeleton_measure;
196
233
  const added = (final?.regions || []).filter(region => !known.has(region.key));
197
234
  if (!added.length) return;
198
235
  const entry = ((measurements[width] ||= {})[locale] ||= { regions: [] });
199
236
  entry.regions = [...entry.regions, ...added];
200
237
  }));
201
238
  settled.forEach((value, index) => {
202
- if (value.status === 'rejected') findings.push(captureFailure(widths[index], locale, value.reason));
239
+ if (value.status === 'rejected') findings.push(captureFailure(widths[index], locale, value.reason, context && named ? { context } : {}));
203
240
  });
204
241
  }
205
242
  }
@@ -225,6 +262,20 @@ async function captureSpaceSkeleton({ library, pool, release, capabilities, time
225
262
  } catch (error) {
226
263
  failed = true; findings.push(captureFailure(null, null, error));
227
264
  }
265
+ // The reader's loading state: the list answers, the opened item's reads stay held. A view that opens nothing
266
+ // with these params is static there and adds nothing.
267
+ const readers = [];
268
+ for (const value of contexts.filter(item => item.open)) {
269
+ const extra = { state: 'reader', ...(named ? { context: value.name } : {}) };
270
+ for (const locale of locales) {
271
+ const settled = await Promise.allSettled(widths.map(width => render(width, { pending: { hold: READER_HOLDS }, locale,
272
+ ...(document ? { skeleton: document } : {}) }, undefined, value.name)));
273
+ settled.forEach((result, index) => {
274
+ if (result.status === 'rejected') { findings.push(captureFailure(widths[index], locale, result.reason, extra)); return; }
275
+ readers.push({ width: widths[index], locale, extra, shown: result.value });
276
+ });
277
+ }
278
+ }
228
279
  for (const combo of combos) {
229
280
  const shown = combo.checked || combo.first;
230
281
  if (!shown) continue;
@@ -237,7 +288,16 @@ async function captureSpaceSkeleton({ library, pool, release, capabilities, time
237
288
  const png = Buffer.from(shown.screenshot.data_base64, 'base64');
238
289
  screenshots.push({ width: combo.width, locale: combo.locale, png, sha256: sha256(png) });
239
290
  }
291
+ for (const { width, locale, extra, shown } of readers) {
292
+ if (!shown?.pending || shown.pending.static) continue;
293
+ try {
294
+ findings.push(...library.runSkeletonChecks({ width, locale, pending: shown.pending, regions: [] }).map(finding => ({ ...finding, ...extra })));
295
+ } catch (error) { findings.push(captureFailure(width, locale, error, extra)); }
296
+ if (!shown.screenshot?.data_base64) continue;
297
+ const png = Buffer.from(shown.screenshot.data_base64, 'base64');
298
+ screenshots.push({ width, locale, ...extra, png, sha256: sha256(png) });
299
+ }
240
300
  const status = document ? 'captured' : failed ? 'failed' : 'none';
241
301
  return { document, screenshots, skeleton: { status, audience, regions: document ? Object.keys(document.regions).sort() : [], findings,
242
- pending_screenshots: screenshots.map(({ width, locale, sha256: digest }) => ({ width, locale, sha256: digest })) } };
302
+ pending_screenshots: screenshots.map(({ png: _png, ...value }) => value) } };
243
303
  }