@malloy-publisher/sdk 0.17.0 → 0.17.1

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 +32 -50
  2. package/dist/{RenderedResult-BcEDcw0V.es.js → RenderedResult-CYJ2Y9Fm.es.js} +24 -24
  3. package/dist/{RenderedResult-uT2oc6ke.cjs.js → RenderedResult-hRvgFMAF.cjs.js} +1 -1
  4. package/dist/ServerProvider-DeVejmVr.cjs.js +1 -0
  5. package/dist/{ServerProvider-vmEUjlEu.es.js → ServerProvider-DzzfVDg_.es.js} +1314 -1712
  6. package/dist/builder/index.cjs.js +12 -12
  7. package/dist/builder/index.es.js +4 -9
  8. package/dist/client/api.d.ts +54 -505
  9. package/dist/client/configuration.d.ts +1 -1
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.d.ts +1 -1
  12. package/dist/client/index.es.js +132 -144
  13. package/dist/components/Dashboard/DashboardGrid.d.ts +1 -1
  14. package/dist/components/Model/ExplorerPage.d.ts +1 -3
  15. package/dist/components/Model/Model.d.ts +1 -4
  16. package/dist/components/Model/ModelExplorer.d.ts +1 -2
  17. package/dist/components/Package/reportQueries.d.ts +2 -4
  18. package/dist/components/Report/Report.d.ts +20 -9
  19. package/dist/components/{legacy → Report}/malloynb/CellRunnerView.d.ts +13 -16
  20. package/dist/components/Report/malloynb/MalloynbReport.d.ts +11 -0
  21. package/dist/components/{legacy → Report}/malloynb/cellKind.d.ts +1 -1
  22. package/dist/components/ServerProvider.d.ts +1 -3
  23. package/dist/components/drill/drillClauses.d.ts +8 -9
  24. package/dist/components/drill/rowsTarget.d.ts +7 -9
  25. package/dist/components/legacy/index.d.ts +3 -7
  26. package/dist/components/modelPage.d.ts +2 -5
  27. package/dist/hooks/useModelGivens.d.ts +2 -2
  28. package/dist/hooks/useQueryResult.d.ts +7 -0
  29. package/dist/index.cjs.js +33 -33
  30. package/dist/index.es.js +8799 -8903
  31. package/dist/{useCompiledDocument-h5-Kc1Zh.cjs.js → useCompiledDocument-BCr-xB_i.cjs.js} +4 -4
  32. package/dist/{useCompiledDocument-rOwDSK_s.es.js → useCompiledDocument-E0tU5KzP.es.js} +266 -277
  33. package/package.json +1 -1
  34. package/src/components/Dashboard/DashboardGrid.tsx +1 -1
  35. package/src/components/Dashboard/DashboardTile.spec.tsx +1 -1
  36. package/src/components/Model/ExplorerPage.tsx +1 -3
  37. package/src/components/Model/Model.tsx +1 -4
  38. package/src/components/Model/ModelExplorer.tsx +1 -2
  39. package/src/components/Package/Package.tsx +1 -5
  40. package/src/components/Package/reportQueries.ts +3 -15
  41. package/src/components/Report/Report.malloynb.spec.tsx +230 -0
  42. package/src/components/Report/Report.spec.tsx +429 -38
  43. package/src/components/Report/Report.telemetry.spec.tsx +51 -10
  44. package/src/components/Report/Report.tsx +63 -44
  45. package/src/components/{legacy → Report}/malloynb/CellRunnerView.spec.tsx +11 -44
  46. package/src/components/{legacy → Report}/malloynb/CellRunnerView.tsx +63 -107
  47. package/src/components/Report/malloynb/MalloynbReport.tsx +110 -0
  48. package/src/components/{legacy → Report}/malloynb/cellKind.ts +5 -4
  49. package/src/components/ReportBuilder/EditorSurface.tsx +3 -3
  50. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +2 -2
  51. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +0 -4
  52. package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +0 -1
  53. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -3
  54. package/src/components/ReportBuilder/ReportEditor.tsx +1 -1
  55. package/src/components/ReportBuilder/loadMalloy.ts +1 -4
  56. package/src/components/ReportBuilder/useSaveChannel.ts +1 -6
  57. package/src/components/ServerProvider.tsx +0 -4
  58. package/src/components/drill/drillClauses.ts +8 -9
  59. package/src/components/drill/rowsTarget.ts +7 -9
  60. package/src/components/index.ts +2 -3
  61. package/src/components/legacy/index.ts +3 -7
  62. package/src/components/modelPage.ts +2 -5
  63. package/src/hooks/useGivensState.ts +8 -8
  64. package/src/hooks/useModelGivens.ts +2 -2
  65. package/src/hooks/useQueryResult.ts +30 -18
  66. package/test/README.md +4 -4
  67. package/dist/ServerProvider-DDRwHiPz.cjs.js +0 -1
  68. package/dist/components/legacy/Dashboard.d.ts +0 -68
  69. package/dist/components/legacy/malloynb/MalloynbCells.d.ts +0 -13
  70. package/dist/components/legacy/malloynb/Notebook.d.ts +0 -15
  71. package/dist/components/legacy/queryKeys.d.ts +0 -8
  72. package/src/components/legacy/Dashboard.spec.tsx +0 -242
  73. package/src/components/legacy/Dashboard.tsx +0 -181
  74. package/src/components/legacy/malloynb/MalloynbCells.tsx +0 -88
  75. package/src/components/legacy/malloynb/Notebook.layout.spec.tsx +0 -103
  76. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +0 -84
  77. package/src/components/legacy/malloynb/Notebook.spec.tsx +0 -223
  78. package/src/components/legacy/malloynb/Notebook.tsx +0 -46
  79. package/src/components/legacy/queryKeys.ts +0 -26
  80. /package/dist/components/{legacy → Report}/malloynb/NotebookCell.d.ts +0 -0
  81. /package/dist/components/{legacy → Report}/malloynb/runPlan.d.ts +0 -0
  82. /package/dist/components/{legacy → Report}/malloynb/types.d.ts +0 -0
  83. /package/src/components/{legacy → Report}/malloynb/NotebookCell.tsx +0 -0
  84. /package/src/components/{legacy → Report}/malloynb/cellKind.spec.ts +0 -0
  85. /package/src/components/{legacy → Report}/malloynb/runPlan.spec.ts +0 -0
  86. /package/src/components/{legacy → Report}/malloynb/runPlan.ts +0 -0
  87. /package/src/components/{legacy → Report}/malloynb/types.ts +0 -0
@@ -5,11 +5,11 @@
5
5
  * `Report` renders a report of either layout from `GET …/reports/{path}`: a
6
6
  * grid as a dashboard of carded tiles, a linear report as bare tiles top to
7
7
  * bottom, and a report written as `run:` cells cell by cell, through the
8
- * governed query endpoint. It runs nothing through the deprecated notebooks
9
- * routes: a `.malloynb` is the deprecated `Notebook`'s to render.
8
+ * governed query endpoint. A `.malloynb`'s code cells run through the query
9
+ * endpoint too.
10
10
  */
11
- import { beforeEach, describe, expect, it, mock } from "bun:test";
12
- import { render, screen, waitFor } from "@testing-library/react";
11
+ import { beforeEach, describe, expect, it, mock, spyOn } from "bun:test";
12
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
13
13
  import {
14
14
  cacheKeys,
15
15
  clearCache,
@@ -30,20 +30,6 @@ const getReport = mock(
30
30
  _options?: unknown,
31
31
  ) => Promise.resolve({ data: manifest }),
32
32
  );
33
- const executeNotebookCell = mock(
34
- (
35
- _environmentName: string,
36
- _packageName: string,
37
- _path: string,
38
- _cellIndex: number,
39
- _versionId?: string,
40
- _filterParams?: string,
41
- _bypassFilters?: boolean,
42
- _givens?: string,
43
- _options?: unknown,
44
- ): Promise<never> => pending(),
45
- );
46
- const getNotebook = mock((): Promise<never> => pending());
47
33
  const executeQueryModel = mock(
48
34
  (
49
35
  _environmentName: string,
@@ -55,7 +41,6 @@ const executeQueryModel = mock(
55
41
 
56
42
  mockServerProvider({
57
43
  reports: { getReport },
58
- notebooks: { getNotebook, executeNotebookCell },
59
44
  models: { executeQueryModel, getModel: () => pending() },
60
45
  });
61
46
 
@@ -73,13 +58,7 @@ const TILES = {
73
58
 
74
59
  beforeEach(() => {
75
60
  clearCache();
76
- for (const fn of [
77
- getReport,
78
- executeNotebookCell,
79
- getNotebook,
80
- executeQueryModel,
81
- ])
82
- fn.mockClear();
61
+ for (const fn of [getReport, executeQueryModel]) fn.mockClear();
83
62
  });
84
63
 
85
64
  describe("the manifest fetch", () => {
@@ -189,6 +168,112 @@ describe("the host's actions", () => {
189
168
  });
190
169
  });
191
170
 
171
+ // Ported from the removed `Dashboard` wrapper's spec: a version that reaches
172
+ // the manifest read but not what the manifest drives lets two versions of one
173
+ // report share cache entries, and one silently serves the other's data.
174
+ describe("the version reaches what the manifest drives", () => {
175
+ const VERSIONED: ReportManifest = {
176
+ path: "ops.malloy",
177
+ name: "ops",
178
+ title: "Ops",
179
+ layout: "grid",
180
+ tiles: [{ kind: "query", query: "orders -> overview" }],
181
+ givens: [
182
+ { name: "REGION", type: "string" },
183
+ {
184
+ name: "TIER",
185
+ control: "select",
186
+ suggest: { source: "orders", dimension: "tier" },
187
+ },
188
+ ],
189
+ } as ReportManifest;
190
+
191
+ const reportAt = (versionId: string) => (
192
+ <Report resourceUri={`${URI}?versionId=${versionId}`} path="ops.malloy" />
193
+ );
194
+
195
+ /** The latest tile request, told apart from a suggest by its `givens`. */
196
+ const tileRequest = () =>
197
+ executeQueryModel.mock.calls
198
+ .map((call) => call[3])
199
+ .filter(
200
+ (request) =>
201
+ typeof request === "object" &&
202
+ request !== null &&
203
+ "givens" in request,
204
+ )
205
+ .at(-1) as
206
+ | { versionId?: string; givens?: Record<string, string> }
207
+ | undefined;
208
+
209
+ beforeEach(() => {
210
+ manifest = VERSIONED;
211
+ });
212
+
213
+ it("runs the tile's query against the same version", async () => {
214
+ render(reportAt("v2"), { wrapper: serverWrapper });
215
+
216
+ await waitFor(() => expect(cacheKeys("queryResult").length).toBe(1));
217
+ expect(tileRequest()?.versionId).toBe("v2");
218
+ expect(cacheKeys("queryResult")[0]).toContain('"v2"');
219
+ });
220
+
221
+ it("runs every tile of a composite report against the same version", async () => {
222
+ manifest = {
223
+ ...VERSIONED,
224
+ tiles: [
225
+ { kind: "query", query: "orders -> by_month" },
226
+ { kind: "query", query: "orders -> by_region" },
227
+ ],
228
+ } as ReportManifest;
229
+ render(reportAt("v2"), { wrapper: serverWrapper });
230
+
231
+ await waitFor(() => expect(cacheKeys("queryResult").length).toBe(2));
232
+ for (const key of cacheKeys("queryResult")) expect(key).toContain('"v2"');
233
+ });
234
+
235
+ it("runs the control's suggest query against the same version", async () => {
236
+ render(reportAt("v2"), { wrapper: serverWrapper });
237
+
238
+ await waitFor(() => expect(cacheKeys("givenSuggest").length).toBe(1));
239
+ expect(cacheKeys("givenSuggest")[0]).toContain('"v2"');
240
+ });
241
+
242
+ it("does not carry one version's applied values into another", async () => {
243
+ // `documentKey` is what tells the givens state the document changed.
244
+ // Mounted with no `givens` prop, which is the case the key governs. v2
245
+ // is read first so that switching back to it is served from the cache:
246
+ // the view stays mounted across the switch, and only the key can reset
247
+ // the values (a fresh read would remount it and reset them anyway).
248
+ const { rerender } = render(reportAt("v2"), { wrapper: serverWrapper });
249
+ await waitFor(() => expect(cacheKeys("queryResult").length).toBe(1));
250
+ rerender(reportAt("v1"));
251
+ await waitFor(() => expect(cacheKeys("queryResult").length).toBe(2));
252
+
253
+ // The control sits in its filter button's popover.
254
+ fireEvent.click(await screen.findByRole("button", { name: /^REGION: / }));
255
+ fireEvent.change(await screen.findByLabelText("REGION"), {
256
+ target: { value: "CA" },
257
+ });
258
+ await waitFor(() =>
259
+ expect(tileRequest()?.givens).toEqual({ REGION: "CA" }),
260
+ );
261
+
262
+ rerender(reportAt("v2"));
263
+
264
+ await waitFor(() =>
265
+ expect(
266
+ // The popover is still open, so the bar behind it is aria-hidden.
267
+ screen.getByRole("button", { name: /^REGION: /, hidden: true })
268
+ .textContent,
269
+ ).not.toContain("CA"),
270
+ );
271
+ const v2 = cacheKeys("queryResult").filter((key) => key.includes('"v2"'));
272
+ expect(v2.length).toBeGreaterThan(0);
273
+ for (const key of v2) expect(key).not.toContain("CA");
274
+ });
275
+ });
276
+
192
277
  describe("rendering by layout", () => {
193
278
  it("draws a grid report's tiles as cards, run against the report's path", async () => {
194
279
  manifest = { ...TILES, layout: "grid" };
@@ -246,30 +331,336 @@ describe("rendering by layout", () => {
246
331
  // DEPRECATED FEATURE COVERAGE — delete together with
247
332
  // `.malloynb` notebooks (see RELEASE_NOTES deprecations).
248
333
  describe("deprecated: .malloynb notebooks", () => {
249
- it("says a .malloynb is Notebook's to render, and runs nothing", async () => {
334
+ const LEGACY = {
335
+ path: "notebooks/legacy.malloynb",
336
+ name: "legacy",
337
+ layout: "linear",
338
+ editable: false,
339
+ notebook: {
340
+ format: "malloynb",
341
+ notebookCells: [
342
+ { type: "markdown", text: "Legacy prose" },
343
+ {
344
+ type: "code",
345
+ text: 'import "../orders.malloy"\nsource: big is orders extend { where: amount > 100 }',
346
+ },
347
+ {
348
+ type: "code",
349
+ text: '##! experimental.givens\nimport "../orders.malloy"\n# bar_chart\nrun: orders -> by_month',
350
+ runQuery: "# bar_chart\nrun: orders -> by_month",
351
+ },
352
+ {
353
+ type: "code",
354
+ text: "run: big -> { aggregate: n is count() }",
355
+ runQuery: "run: big -> { aggregate: n is count() }",
356
+ },
357
+ ],
358
+ sources: [
359
+ { name: "orders", givens: [{ name: "REGION", type: "string" }] },
360
+ ],
361
+ },
362
+ } as ReportManifest;
363
+
364
+ /** The query requests the cells sent, in the order they were sent. */
365
+ const cellRequests = () =>
366
+ executeQueryModel.mock.calls.map(
367
+ ([environmentName, packageName, modelPath, request]) => ({
368
+ environmentName,
369
+ packageName,
370
+ modelPath,
371
+ request,
372
+ }),
373
+ );
374
+
375
+ beforeEach(() => {
376
+ manifest = LEGACY;
377
+ });
378
+
379
+ it("draws its markdown and its code cells, each code cell with its result", async () => {
380
+ executeQueryModel.mockImplementation(
381
+ () => Promise.resolve({ data: { result: "{}" } }) as Promise<never>,
382
+ );
383
+ try {
384
+ render(
385
+ <Report resourceUri={URI} path="notebooks/legacy.malloynb" />,
386
+ { wrapper: serverWrapper },
387
+ );
388
+
389
+ expect(await screen.findByText("Legacy prose")).toBeTruthy();
390
+ // One result tile, with its code behind a button, per cell that runs.
391
+ await waitFor(() =>
392
+ expect(
393
+ screen.getAllByRole("button", { name: "Malloy code" }),
394
+ ).toHaveLength(2),
395
+ );
396
+ } finally {
397
+ executeQueryModel.mockImplementation(() => pending());
398
+ }
399
+ });
400
+
401
+ it("runs each code cell's run: through the query endpoint, against the notebook's path, with the givens and the version", async () => {
402
+ render(
403
+ <Report
404
+ resourceUri={`${URI}?versionId=v2`}
405
+ path="notebooks/legacy.malloynb"
406
+ givens={{ REGION: "West" }}
407
+ />,
408
+ { wrapper: serverWrapper },
409
+ );
410
+
411
+ await waitFor(() =>
412
+ expect(executeQueryModel).toHaveBeenCalledTimes(2),
413
+ );
414
+ const sent = cellRequests();
415
+ // The declaration-only cell is not sent; the others send their run:,
416
+ // render tag included, without their imports and flags.
417
+ expect(
418
+ sent.map((call) => (call.request as { query: string }).query),
419
+ ).toEqual([
420
+ "# bar_chart\nrun: orders -> by_month",
421
+ "run: big -> { aggregate: n is count() }",
422
+ ]);
423
+ for (const call of sent) {
424
+ expect(call).toEqual({
425
+ environmentName: "env",
426
+ packageName: "pkg",
427
+ modelPath: "notebooks/legacy.malloynb",
428
+ request: {
429
+ query: expect.any(String),
430
+ versionId: "v2",
431
+ givens: { REGION: "West" },
432
+ },
433
+ });
434
+ }
435
+ });
436
+
437
+ it("sends each code cell's served runQuery as it is, and reads no cell's text for one", async () => {
438
+ const chart = "#| bar_chart {\n size: lg\n|#\nrun: s -> v";
439
+ const markdown =
440
+ "#|(markdown)\nRevenue (USD, by region\n|#\nrun: s -> v";
441
+ const filter = [
442
+ "run: s -> {",
443
+ " where: label ~ f'''",
444
+ " \\} source: x",
445
+ " '''",
446
+ " aggregate: n",
447
+ "}",
448
+ ].join("\n");
449
+ const unicode = "run: importé -> by_region";
250
450
  manifest = {
251
- path: "legacy.malloynb",
252
- name: "legacy",
253
- layout: "linear",
254
- editable: false,
451
+ ...LEGACY,
255
452
  notebook: {
256
453
  format: "malloynb",
257
454
  notebookCells: [
258
- { type: "markdown", text: "Legacy prose" },
259
- { type: "code", text: "run: orders -> by_month" },
455
+ { type: "code", text: chart, runQuery: chart },
456
+ { type: "code", text: markdown, runQuery: markdown },
457
+ { type: "code", text: filter, runQuery: filter },
458
+ { type: "code", text: unicode, runQuery: unicode },
459
+ {
460
+ type: "code",
461
+ text: "run: a -> v\n#|(markdown)\nthen run: b -> v\n|#\nsource: t is s",
462
+ runQuery: "run: a -> v",
463
+ },
464
+ // No runQuery served: nothing to run, whatever the text says.
465
+ { type: "code", text: "run: s -> v" },
260
466
  ],
261
467
  },
262
468
  } as ReportManifest;
263
- render(<Report resourceUri={URI} path="legacy.malloynb" />, {
469
+ // Answered, since only four cells run at once.
470
+ executeQueryModel.mockImplementation(
471
+ () => Promise.resolve({ data: { result: "{}" } }) as Promise<never>,
472
+ );
473
+ try {
474
+ render(
475
+ <Report resourceUri={URI} path="notebooks/legacy.malloynb" />,
476
+ { wrapper: serverWrapper },
477
+ );
478
+
479
+ await waitFor(() =>
480
+ expect(executeQueryModel).toHaveBeenCalledTimes(5),
481
+ );
482
+ await new Promise((resolve) => setTimeout(resolve, 20));
483
+ expect(
484
+ cellRequests().map(
485
+ (call) => (call.request as { query: string }).query,
486
+ ),
487
+ ).toEqual([chart, markdown, filter, unicode, "run: a -> v"]);
488
+ } finally {
489
+ executeQueryModel.mockImplementation(() => pending());
490
+ }
491
+ });
492
+
493
+ it("keeps each cell's answer under a tile's query key, so a remount within the cache window does not ask again", async () => {
494
+ executeQueryModel.mockImplementation(
495
+ () => Promise.resolve({ data: { result: "{}" } }) as Promise<never>,
496
+ );
497
+ try {
498
+ const first = render(
499
+ <Report resourceUri={URI} path="notebooks/legacy.malloynb" />,
500
+ { wrapper: serverWrapper },
501
+ );
502
+ await waitFor(() =>
503
+ expect(
504
+ screen.getAllByRole("button", { name: "Malloy code" }),
505
+ ).toHaveLength(2),
506
+ );
507
+ expect(executeQueryModel).toHaveBeenCalledTimes(2);
508
+ expect(cacheKeys("queryResult")).toContain(
509
+ '["queryResult","env","pkg",null,"notebooks/legacy.malloynb",null,"run: big -> { aggregate: n is count() }",null,"{}","http://localhost/api/v0"]',
510
+ );
511
+ first.unmount();
512
+
513
+ render(
514
+ <Report resourceUri={URI} path="notebooks/legacy.malloynb" />,
515
+ { wrapper: serverWrapper },
516
+ );
517
+ await waitFor(() =>
518
+ expect(
519
+ screen.getAllByRole("button", { name: "Malloy code" }),
520
+ ).toHaveLength(2),
521
+ );
522
+ await new Promise((resolve) => setTimeout(resolve, 20));
523
+ expect(executeQueryModel).toHaveBeenCalledTimes(2);
524
+ } finally {
525
+ executeQueryModel.mockImplementation(() => pending());
526
+ }
527
+ });
528
+
529
+ it("cancels a cell's request when the report goes away, and caches nothing for it", async () => {
530
+ let signal: AbortSignal | undefined;
531
+ executeQueryModel.mockImplementation(((..._args: unknown[]) => {
532
+ signal = (_args[6] as { signal?: AbortSignal } | undefined)?.signal;
533
+ return pending();
534
+ }) as never);
535
+ try {
536
+ const view = render(
537
+ <Report resourceUri={URI} path="notebooks/legacy.malloynb" />,
538
+ { wrapper: serverWrapper },
539
+ );
540
+ await waitFor(() =>
541
+ expect(executeQueryModel).toHaveBeenCalledTimes(2),
542
+ );
543
+ expect(signal?.aborted).toBe(false);
544
+ view.unmount();
545
+ await waitFor(() => expect(signal?.aborted).toBe(true));
546
+ const states = globalQueryClient
547
+ .getQueryCache()
548
+ .findAll({ queryKey: ["queryResult"] })
549
+ .map((query) => query.state.data);
550
+ expect(states.every((data) => data === undefined)).toBe(true);
551
+ } finally {
552
+ executeQueryModel.mockImplementation(() => pending());
553
+ }
554
+ });
555
+
556
+ it("sends no givens when none is set", async () => {
557
+ render(<Report resourceUri={URI} path="notebooks/legacy.malloynb" />, {
264
558
  wrapper: serverWrapper,
265
559
  });
266
560
 
561
+ await waitFor(() =>
562
+ expect(executeQueryModel).toHaveBeenCalledTimes(2),
563
+ );
564
+ for (const { request } of cellRequests()) {
565
+ expect(request).toEqual({
566
+ query: expect.any(String),
567
+ versionId: undefined,
568
+ });
569
+ }
570
+ });
571
+
572
+ it("draws the host's actions, on a row of their own above the cells", async () => {
573
+ render(
574
+ <Report
575
+ resourceUri={URI}
576
+ path="notebooks/legacy.malloynb"
577
+ actions={<button type="button">Download</button>}
578
+ />,
579
+ { wrapper: serverWrapper },
580
+ );
581
+
582
+ const prose = await screen.findByText("Legacy prose");
583
+ const action = screen.getByRole("button", { name: "Download" });
584
+ // Above the notebook's first cell, which is its title.
267
585
  expect(
268
- await screen.findByText(/render it with Notebook/),
586
+ action.compareDocumentPosition(prose) &
587
+ Node.DOCUMENT_POSITION_FOLLOWING,
269
588
  ).toBeTruthy();
270
- expect(screen.queryByText("Legacy prose")).toBeNull();
271
- expect(executeNotebookCell).not.toHaveBeenCalled();
272
- expect(executeQueryModel).not.toHaveBeenCalled();
589
+ });
590
+
591
+ it("runs the cells with a ## givens starting value, and keeps it out of what it reports to the host", async () => {
592
+ manifest = {
593
+ ...LEGACY,
594
+ notebook: {
595
+ ...LEGACY.notebook,
596
+ startingGivens: { REGION: "East" },
597
+ },
598
+ } as ReportManifest;
599
+ const onGivensChange = mock(() => {});
600
+ render(
601
+ <Report
602
+ resourceUri={URI}
603
+ path="notebooks/legacy.malloynb"
604
+ onGivensChange={onGivensChange}
605
+ />,
606
+ { wrapper: serverWrapper },
607
+ );
608
+
609
+ await waitFor(() =>
610
+ expect(executeQueryModel).toHaveBeenCalledTimes(2),
611
+ );
612
+ for (const { request } of cellRequests()) {
613
+ expect(request).toMatchObject({ givens: { REGION: "East" } });
614
+ }
615
+ // `Report` mounts the cells only once the manifest has arrived, so
616
+ // the starting value is the controls' first state and is never
617
+ // reported as a change for the host to write into its URL.
618
+ expect(onGivensChange).not.toHaveBeenCalled();
619
+ });
620
+
621
+ it("shows a cell's failure in that cell, and still runs the others", async () => {
622
+ const quiet = spyOn(console, "error").mockImplementation(() => {});
623
+ executeQueryModel.mockImplementation(((
624
+ _environmentName: string,
625
+ _packageName: string,
626
+ _modelPath: string,
627
+ request: unknown,
628
+ ) =>
629
+ (request as { query: string }).query.startsWith("run: big")
630
+ ? Promise.reject(
631
+ Object.assign(
632
+ new Error("Request failed with status code 404"),
633
+ {
634
+ response: {
635
+ data: {
636
+ message: "Query target is not queryable.",
637
+ },
638
+ },
639
+ },
640
+ ),
641
+ )
642
+ : Promise.resolve({ data: { result: "{}" } })) as never);
643
+ try {
644
+ render(
645
+ <Report resourceUri={URI} path="notebooks/legacy.malloynb" />,
646
+ { wrapper: serverWrapper },
647
+ );
648
+
649
+ expect(
650
+ await screen.findByText("Query target is not queryable."),
651
+ ).toBeTruthy();
652
+ expect(
653
+ screen.getAllByText("This cell could not be run."),
654
+ ).toHaveLength(1);
655
+ await waitFor(() =>
656
+ expect(
657
+ screen.getAllByRole("button", { name: "Malloy code" }),
658
+ ).toHaveLength(1),
659
+ );
660
+ } finally {
661
+ executeQueryModel.mockImplementation(() => pending());
662
+ quiet.mockRestore();
663
+ }
273
664
  });
274
665
  });
275
666
  });
@@ -194,12 +194,25 @@ describe("opening a report", () => {
194
194
  // DEPRECATED FEATURE COVERAGE — delete together with
195
195
  // `.malloynb` notebooks (see RELEASE_NOTES deprecations).
196
196
  describe("deprecated: .malloynb notebooks", () => {
197
- it("reports a .malloynb as unsupported rather than opened", async () => {
198
- manifest = {
199
- ...CELLS,
200
- path: "legacy.malloynb",
201
- notebook: { ...CELLS.notebook, format: "malloynb" },
202
- } as ReportManifest;
197
+ const LEGACY = {
198
+ ...CELLS,
199
+ path: "legacy.malloynb",
200
+ notebook: {
201
+ format: "malloynb",
202
+ notebookCells: [
203
+ { type: "markdown", text: "Cell prose" },
204
+ { type: "code", text: 'import "orders.malloy"' },
205
+ {
206
+ type: "code",
207
+ text: "run: orders -> by_month",
208
+ runQuery: "run: orders -> by_month",
209
+ },
210
+ ],
211
+ },
212
+ } as ReportManifest;
213
+
214
+ it("reports a .malloynb as opened, counting the cells it runs", async () => {
215
+ manifest = LEGACY;
203
216
  const onEvent = mock((_event: ReportEvent) => {});
204
217
  render(
205
218
  <Report
@@ -210,10 +223,38 @@ describe("opening a report", () => {
210
223
  { wrapper: serverWrapper },
211
224
  );
212
225
  await waitFor(() => expect(onEvent).toHaveBeenCalled());
213
- expect(typesOf(onEvent.mock.calls)).toEqual(["report.load_failed"]);
214
- expect(onEvent.mock.calls[0][0]).toMatchObject({
215
- category: "unsupported",
216
- });
226
+ expect(typesOf(onEvent.mock.calls)).toEqual(["report.opened"]);
227
+ expect(onEvent.mock.calls[0][0]).toMatchObject({ tiles: 1 });
228
+ });
229
+
230
+ it("reports a .malloynb cell's failed query by the cell's position", async () => {
231
+ manifest = LEGACY;
232
+ queryFailure = { response: { status: 500 } };
233
+ const onEvent = mock((_event: ReportEvent) => {});
234
+ render(
235
+ <Report
236
+ resourceUri={URI}
237
+ path="legacy.malloynb"
238
+ onEvent={onEvent}
239
+ />,
240
+ { wrapper: serverWrapper },
241
+ );
242
+ await waitFor(() =>
243
+ expect(typesOf(onEvent.mock.calls)).toContain(
244
+ "report.query_failed",
245
+ ),
246
+ );
247
+ expect(
248
+ onEvent.mock.calls
249
+ .map(([event]) => event)
250
+ .filter((event) => event.type === "report.query_failed"),
251
+ ).toEqual([
252
+ expect.objectContaining({
253
+ tile: 2,
254
+ category: "server",
255
+ path: "legacy.malloynb",
256
+ }),
257
+ ]);
217
258
  });
218
259
  });
219
260
  });