@malloy-publisher/sdk 0.8.3 → 0.8.4

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 (40) hide show
  1. package/README.md +14 -65
  2. package/dist/{DocumentStorage-CigwNjz4.es.js → Dashboard-DnqWRijB.es.js} +23660 -23575
  3. package/dist/Dashboard-FD3-Af-_.cjs.js +136 -0
  4. package/dist/{RenderedResult-BfayOSk1.es.js → RenderedResult-6UKAHaAj.es.js} +18 -18
  5. package/dist/{RenderedResult-DpHdrFtp.cjs.js → RenderedResult-CetSzFgW.cjs.js} +1 -1
  6. package/dist/ServerProvider-BsjJvkML.cjs.js +1 -0
  7. package/dist/{ServerProvider-CfUFleYe.es.js → ServerProvider-DgRFJ43L.es.js} +983 -957
  8. package/dist/builder/index.cjs.js +50 -50
  9. package/dist/builder/index.es.js +2587 -2511
  10. package/dist/client/api.d.ts +141 -40
  11. package/dist/client/configuration.d.ts +1 -1
  12. package/dist/client/index.cjs.js +1 -1
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/index.es.js +62 -59
  15. package/dist/components/DashboardBuilder/malloyText.d.ts +49 -0
  16. package/dist/components/DashboardBuilder/malloyTree.d.ts +2 -18
  17. package/dist/components/DashboardBuilder/readDocument.d.ts +2 -0
  18. package/dist/components/Notebook/NotebookCell.d.ts +3 -2
  19. package/dist/components/Notebook/cellKind.d.ts +20 -0
  20. package/dist/index.cjs.js +15 -12
  21. package/dist/index.es.js +4528 -4435
  22. package/package.json +1 -1
  23. package/src/components/DashboardBuilder/malloyText.spec.ts +70 -1
  24. package/src/components/DashboardBuilder/malloyText.ts +171 -3
  25. package/src/components/DashboardBuilder/malloyTree.spec.ts +35 -0
  26. package/src/components/DashboardBuilder/malloyTree.ts +28 -4
  27. package/src/components/DashboardBuilder/readDocument.spec.ts +180 -1
  28. package/src/components/DashboardBuilder/readDocument.ts +52 -14
  29. package/src/components/DashboardBuilder/spliceDocument.spec.ts +396 -2
  30. package/src/components/DashboardBuilder/spliceDocument.ts +121 -18
  31. package/src/components/Notebook/Notebook.served.spec.tsx +175 -0
  32. package/src/components/Notebook/Notebook.spec.tsx +33 -2
  33. package/src/components/Notebook/Notebook.tsx +13 -7
  34. package/src/components/Notebook/NotebookCell.tsx +124 -63
  35. package/src/components/Notebook/cellKind.spec.ts +191 -0
  36. package/src/components/Notebook/cellKind.ts +74 -0
  37. package/src/components/Package/Package.notebooks.spec.tsx +90 -0
  38. package/src/components/Package/Package.tsx +18 -4
  39. package/dist/DocumentStorage-DvUNSOiN.cjs.js +0 -134
  40. package/dist/ServerProvider-CuYLH_Yi.cjs.js +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.8.3",
4
+ "version": "0.8.4",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -2,7 +2,14 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
- import { artifactLine, isIdentifier, tileSteps } from "./malloyText";
5
+ import {
6
+ artifactLine,
7
+ blockSpans,
8
+ closesBlock,
9
+ isIdentifier,
10
+ markdownNote,
11
+ tileSteps,
12
+ } from "./malloyText";
6
13
 
7
14
  /**
8
15
  * What is left here reads the two grammars that are not Malloy's. The shapes
@@ -43,3 +50,65 @@ describe("the model-level ## lines", () => {
43
50
  expect(artifactLine(["source: a is b"])).toBe(-1);
44
51
  });
45
52
  });
53
+
54
+ describe("markdownNote", () => {
55
+ it("reads Malloy's route from the first token, in every bracket form", () => {
56
+ expect(markdownNote("#(markdown) x")).toEqual({ level: 1, block: false });
57
+ expect(markdownNote(" ##[markdown]")).toEqual({
58
+ level: 2,
59
+ block: false,
60
+ });
61
+ expect(markdownNote("#|<markdown>")).toEqual({ level: 1, block: true });
62
+ expect(markdownNote("##|{markdown} x")).toEqual({
63
+ level: 2,
64
+ block: true,
65
+ });
66
+ });
67
+
68
+ it("refuses a malformed or different route", () => {
69
+ for (const line of [
70
+ "#(markdown)hi",
71
+ "#(markdown]",
72
+ "#markdown x",
73
+ "#(Markdown) x",
74
+ "#(markdown_help) x",
75
+ "#(doc) x",
76
+ "# (markdown)",
77
+ "###(markdown)",
78
+ ])
79
+ expect(markdownNote(line)).toBeUndefined();
80
+ });
81
+ });
82
+
83
+ describe("closesBlock", () => {
84
+ it("wants the opener's own column", () => {
85
+ expect(closesBlock("|#", 0, "|#")).toBe(true);
86
+ expect(closesBlock(" |#", 0, "|#")).toBe(false);
87
+ expect(closesBlock(" |#", 2, "|#")).toBe(true);
88
+ expect(closesBlock("|#", 2, "|#")).toBe(false);
89
+ expect(closesBlock(" |#", 2, "|#")).toBe(false);
90
+ expect(closesBlock(" |#", undefined, "|#")).toBe(true);
91
+ });
92
+
93
+ it("never closes a `#|` block on `|##`", () => {
94
+ expect(closesBlock("|##", 0, "|#")).toBe(false);
95
+ expect(closesBlock("|##", 0, "|##")).toBe(true);
96
+ expect(closesBlock("|# tail", 0, "|#")).toBe(true);
97
+ });
98
+ });
99
+
100
+ describe("blockSpans", () => {
101
+ it("closes on the opener's column and skips openers a comment holds", () => {
102
+ const lines = [
103
+ " #|(markdown)",
104
+ "|# wrong column",
105
+ " |## wrong closer",
106
+ " |#",
107
+ "/*",
108
+ "#| in a comment",
109
+ "|#",
110
+ "*/",
111
+ ];
112
+ expect(blockSpans(lines, (i) => i >= 4)).toEqual([[0, 3]]);
113
+ });
114
+ });
@@ -12,11 +12,179 @@ const IDENT = "[A-Za-z_][A-Za-z0-9_]*";
12
12
  export const isIdentifier = (text: string) =>
13
13
  new RegExp(`^${IDENT}$`).test(text);
14
14
 
15
+ /** The server's rule for the tag line: `## artifact` at the start of a line. */
16
+ export const ARTIFACT_LINE = /^##[ \t]*artifact\b/;
17
+
18
+ /**
19
+ * A note's markdown route, by Malloy's prefix rule: the first whitespace-delimited token is
20
+ * `#`/`##`, an optional `|`, and `(markdown)` or its `<>`, `[]`, `{}` twin. `#(markdown)hi` has
21
+ * trailing junk on the prefix, which Malloy calls malformed and the server ignores.
22
+ */
23
+ export function markdownNote(
24
+ line: string,
25
+ ): { level: 1 | 2; block: boolean } | undefined {
26
+ const token = line.trim().split(/[ \t\r]/, 1)[0];
27
+ const m =
28
+ /^(#{1,2})(\|?)(?:\(markdown\)|<markdown>|\[markdown\]|\{markdown\})$/.exec(
29
+ token,
30
+ );
31
+ return m ? { level: m[1].length as 1 | 2, block: m[2] === "|" } : undefined;
32
+ }
33
+
34
+ /**
35
+ * Whether `line` closes a block annotation as Malloy's lexer reads it: the closer sits at the
36
+ * opener's own column, and `|##` never closes a `#|` block. An unknown `column` (a cell's first
37
+ * line has lost its indentation) accepts any indent.
38
+ */
39
+ export function closesBlock(
40
+ line: string,
41
+ column: number | undefined,
42
+ closer: "|#" | "|##",
43
+ ): boolean {
44
+ const indent = /^[ \t]*/.exec(line)[0].length;
45
+ if (column !== undefined && indent !== column) return false;
46
+ const rest = line.slice(indent);
47
+ return (
48
+ rest.startsWith(closer) && (closer !== "|#" || rest.charAt(2) !== "#")
49
+ );
50
+ }
51
+
52
+ /**
53
+ * The `##|` / `#|` blocks that have a closer, as `[opener line, closer line]`;
54
+ * an opener with none is not a block. An opener on a `skip` line (inside a
55
+ * block comment) opens nothing.
56
+ */
57
+ export function blockSpans(
58
+ lines: string[],
59
+ skip?: (line: number) => boolean,
60
+ ): [number, number][] {
61
+ const spans: [number, number][] = [];
62
+ for (let i = 0; i < lines.length; i++) {
63
+ if (skip?.(i)) continue;
64
+ const opener = /^([ \t]*)(#{1,2})\|/.exec(lines[i]);
65
+ if (!opener) continue;
66
+ const closer = opener[2] === "#" ? "|#" : "|##";
67
+ for (let j = i + 1; j < lines.length; j++) {
68
+ if (closesBlock(lines[j], opener[1].length, closer)) {
69
+ spans.push([i, j]);
70
+ i = j;
71
+ break;
72
+ }
73
+ }
74
+ }
75
+ return spans;
76
+ }
77
+
78
+ /** The lines that sit inside or on a block, where prose is not a tag or a note. */
79
+ export function blockLines(lines: string[]): Set<number> {
80
+ const out = new Set<number>();
81
+ for (const [from, to] of blockSpans(lines))
82
+ for (let i = from; i <= to; i++) out.add(i);
83
+ return out;
84
+ }
85
+
86
+ /**
87
+ * The `#(markdown)` lines and `#|(markdown)` blocks: prose attached to a declaration, not tags.
88
+ * A line inside a block comment (`skip`) or inside another block is no annotation.
89
+ */
90
+ export function markdownLines(
91
+ lines: string[],
92
+ skip?: (line: number) => boolean,
93
+ ): Set<number> {
94
+ const out = new Set<number>();
95
+ const inside = new Set<number>();
96
+ for (const [from, to] of blockSpans(lines, skip)) {
97
+ const attached = markdownNote(lines[from])?.level === 1;
98
+ for (let i = from; i <= to; i++) {
99
+ inside.add(i);
100
+ if (attached) out.add(i);
101
+ }
102
+ }
103
+ lines.forEach((l, i) => {
104
+ if (inside.has(i) || skip?.(i)) return;
105
+ const note = markdownNote(l);
106
+ if (note?.level === 1 && !note.block) out.add(i);
107
+ });
108
+ return out;
109
+ }
110
+
15
111
  /** The line carrying the model-level `## artifact` tag, or -1. */
16
- export const artifactLine = (lines: string[]) =>
17
- lines.findIndex(
18
- (l) => l.trimStart().startsWith("##") && l.includes("artifact"),
112
+ export const artifactLine = (lines: string[]) => {
113
+ const inBlock = blockLines(lines);
114
+ return lines.findIndex(
115
+ (l, i) => !inBlock.has(i) && ARTIFACT_LINE.test(l.trim()),
19
116
  );
117
+ };
118
+
119
+ /** An unnamed `"` note line; `##"word` is a malformed route Malloy drops. */
120
+ const DOC_NOTE = /^##"([ \t]|$)/;
121
+
122
+ /**
123
+ * The lines a dashboard's description is read from, by the server's rule: the
124
+ * notes above the artifact tag, or, when those carry no prose, the notes below
125
+ * it, `##"` lines and `##|"` blocks alike. `blankAbove` are the prose-less
126
+ * `##"` notes above when the text is read from below, which a rewrite has to
127
+ * clear; `below` are the `##"` notes under the tag, and `belowBlock` is true
128
+ * when a `##|"` block with prose sits there. `inBlock` is true when the text
129
+ * that is read is held in a block, which a rewrite cannot patch.
130
+ */
131
+ export function descriptionNotes(lines: string[]): {
132
+ read: number[];
133
+ blankAbove: number[];
134
+ below: number[];
135
+ belowBlock: boolean;
136
+ inBlock: boolean;
137
+ text?: string;
138
+ } {
139
+ const artifactAt = artifactLine(lines);
140
+ const inside = blockLines(lines);
141
+ const isAbove = (i: number) => artifactAt < 0 || i < artifactAt;
142
+ const isBelow = (i: number) => artifactAt >= 0 && i > artifactAt;
143
+ type Item = { at: number; text: string; block: boolean };
144
+ const items: Item[] = [];
145
+ lines.forEach((l, i) => {
146
+ if (!inside.has(i) && DOC_NOTE.test(l.trim()))
147
+ items.push({ at: i, text: l.trim().slice(3).trim(), block: false });
148
+ });
149
+ for (const [from, to] of blockSpans(lines)) {
150
+ if (!/^[ \t]*##\|"([ \t]|$)/.test(lines[from])) continue;
151
+ const text = [lines[from].trim().slice(4), ...lines.slice(from + 1, to)]
152
+ .map((l) => l.trim())
153
+ .join("\n")
154
+ .trim();
155
+ if (text.length > 0) items.push({ at: from, text, block: true });
156
+ }
157
+ items.sort((a, b) => a.at - b.at);
158
+ const above = items.filter((n) => isAbove(n.at));
159
+ const below = items.filter((n) => isBelow(n.at));
160
+ const chosen = above.some((n) => n.text.trim()) ? above : below;
161
+ const text = chosen.map((n) => n.text).join("\n");
162
+ const lineAts = (from: Item[]) =>
163
+ from.filter((n) => !n.block).map((n) => n.at);
164
+ return {
165
+ read: lineAts(chosen),
166
+ blankAbove: chosen === below ? lineAts(above) : [],
167
+ below: lineAts(below),
168
+ belowBlock: below.some((n) => n.block),
169
+ inBlock: chosen.some((n) => n.block),
170
+ ...(text.trim() ? { text } : {}),
171
+ };
172
+ }
173
+
174
+ /** Whether `tiles=[…]` holds an entry that is not a quoted run expression, such as a `kind=text` tile. */
175
+ export function hasNonQuotedTiles(artifactText: string): boolean {
176
+ const key = artifactText.search(/tiles\s*=\s*\[/);
177
+ if (key < 0) return false;
178
+ const open = artifactText.indexOf("[", key);
179
+ const close = artifactText.indexOf("]", open);
180
+ if (close < 0) return false;
181
+ return (
182
+ artifactText
183
+ .slice(open + 1, close)
184
+ .replace(/"[^"]*"/g, "")
185
+ .replace(/[\s,]/g, "").length > 0
186
+ );
187
+ }
20
188
 
21
189
  /** A tile expression's steps: `orders -> by_brand + { limit: 2 }`. */
22
190
  export interface TileSteps {
@@ -285,6 +285,41 @@ describe("comments", () => {
285
285
  ]);
286
286
  });
287
287
 
288
+ it("moves a declaration with the attached markdown block above its tags", async () => {
289
+ const source =
290
+ "source: s is a extend {\n\n #|(markdown)\n ### Lead tile\n Excludes refunds.\n |#\n # colspan=6\n view: v is x\n}\n";
291
+ const p = await parsed(source);
292
+ expect(p.blockStart(7)).toBe(2);
293
+ });
294
+
295
+ it("stops at a blank line above an attached markdown block", async () => {
296
+ const source =
297
+ "source: s is a extend {\n dimension: d is 1\n\n #|(markdown)\n Notes\n\n more\n |#\n view: v is x\n}\n";
298
+ const p = await parsed(source);
299
+ expect(p.blockStart(8)).toBe(3);
300
+ });
301
+
302
+ it("does not take a closer-looking line in a block comment for a block's end", async () => {
303
+ const source =
304
+ "source: s is a extend {\n #|(markdown)\n Prev\n |#\n view: u is x\n\n # colspan=6\n /*\n |# not a closer\n */\n view: v is x\n}\n";
305
+ const p = await parsed(source);
306
+ expect(p.blockStart(10)).toBe(6);
307
+ });
308
+
309
+ it("starts a block at its opener when a body line begins `#|`", async () => {
310
+ const source =
311
+ "source: s is a extend {\n dimension: d is 1\n #|(markdown)\n Notes\n\n #| body\n |#\n view: v is x\n}\n";
312
+ const p = await parsed(source);
313
+ expect(p.blockStart(7)).toBe(2);
314
+ });
315
+
316
+ it("does not close a `#|` block on `|##` or an indented `|#`", async () => {
317
+ const source =
318
+ "source: s is a extend {\n dimension: d is 1\n #|(markdown)\n |## not it\n |# nor this\n |#\n view: v is x\n}\n";
319
+ const p = await parsed(source);
320
+ expect(p.blockStart(6)).toBe(2);
321
+ });
322
+
288
323
  // `--` starts a comment in Malloy exactly as `//` does.
289
324
  it("reads a dash comment as the block above a declaration", async () => {
290
325
  const p = await parsed(
@@ -20,6 +20,8 @@
20
20
  * minifiers leave alone.
21
21
  */
22
22
 
23
+ import { blockSpans, markdownLines } from "./malloyText";
24
+
23
25
  /** A half-open range of UTF-16 offsets into the source text. */
24
26
  export interface Span {
25
27
  start: number;
@@ -172,6 +174,8 @@ export interface ParsedMalloy {
172
174
  * middle of a `/* … *\/`, whose text is prose however it begins.
173
175
  */
174
176
  commentLine(line: number): boolean;
177
+ /** Whether `line` is part of a `#(markdown)` line or a `#|(markdown)` block, which are prose, not tags. */
178
+ proseLine(line: number): boolean;
175
179
  /**
176
180
  * The `#`/comment block immediately above `line`, stopping at a blank line —
177
181
  * the unit that travels with a declaration when it moves.
@@ -289,6 +293,10 @@ class Reader {
289
293
  * makes the writer rewrite a line inside a comment.
290
294
  */
291
295
  commentLines: ReadonlySet<number> = new Set();
296
+ /** `(markdown)` annotation lines, whose body can start with `#` without being a tag. */
297
+ proseLines: ReadonlySet<number> = new Set();
298
+ /** The `#|` blocks with a closer, as [opener line, closer line]; a comment's lines open none. */
299
+ blocks: [number, number][] = [];
292
300
 
293
301
  constructor(readonly text: string) {
294
302
  this.map = codePointMap(text);
@@ -470,7 +478,7 @@ function readTags(
470
478
  const first = r.line(statement.start);
471
479
  const last = r.line(declStart);
472
480
  for (let i = first; i < last; i++) {
473
- if (r.commentLines.has(i)) continue;
481
+ if (r.commentLines.has(i) || r.proseLines.has(i)) continue;
474
482
  const text: string = r.text
475
483
  .slice(r.lineStarts[i], r.lineStarts[i + 1] ?? r.text.length)
476
484
  .trim();
@@ -776,6 +784,13 @@ export async function parseMalloy(text: string): Promise<ParseResult> {
776
784
  // and a source is read through it.
777
785
  const comments = commentIndex(r, tokenStream);
778
786
  r.commentLines = comments.lines;
787
+ const textLines = text.split("\n");
788
+ const inComment = (line: number) => comments.lines.has(line);
789
+ r.proseLines = markdownLines(textLines, inComment);
790
+ // A `##|` block is a floating note, never part of a declaration's tags.
791
+ r.blocks = blockSpans(textLines, inComment).filter(
792
+ ([from]) => !textLines[from].trimStart().startsWith("##"),
793
+ );
779
794
  const sources = readSources(r, root);
780
795
 
781
796
  // The shape assertion, on real content rather than on the API's presence:
@@ -800,6 +815,7 @@ export async function parseMalloy(text: string): Promise<ParseResult> {
800
815
  trailingComment: (line) => comments.trailing.get(line),
801
816
  comments: comments.all,
802
817
  commentLine: (line) => comments.lines.has(line),
818
+ proseLine: (line) => r.proseLines.has(line),
803
819
  commentIn: (span) =>
804
820
  comments.all.find(
805
821
  (at) => at.start >= span.start && at.start < span.end,
@@ -939,11 +955,19 @@ function blockStart(
939
955
  commentLines: Set<number>,
940
956
  line: number,
941
957
  ): number {
942
- let start = line;
943
- for (let i = line - 1; i >= 0; i--) {
944
- const text = r.text
958
+ const lineText = (i: number) =>
959
+ r.text
945
960
  .slice(r.lineStarts[i], r.lineStarts[i + 1] ?? r.text.length)
946
961
  .trim();
962
+ let start = line;
963
+ for (let i = line - 1; i >= 0; i--) {
964
+ const text = lineText(i);
965
+ // A `#|` block's body lines are not `#` lines, so its closer pulls in the whole block.
966
+ const block = r.blocks.find(([, to]) => to === i);
967
+ if (block) {
968
+ start = i = block[0];
969
+ continue;
970
+ }
947
971
  // A blank line is the boundary -- unless it is inside a block comment,
948
972
  // where it is the author's paragraph break rather than their separator.
949
973
  if (text === "" && !commentLines.has(i)) break;
@@ -86,6 +86,59 @@ describe("blockAbove", () => {
86
86
  expect(at.tags).toEqual([]);
87
87
  });
88
88
 
89
+ it("leaves an attached markdown block and line out of the tags, whatever its body starts with", async () => {
90
+ const source = [
91
+ "source: s is a extend {",
92
+ "",
93
+ " #|(markdown)",
94
+ " # Lead tile",
95
+ " |#",
96
+ " #(markdown) a note",
97
+ " # colspan=6",
98
+ " view: revenue is sales",
99
+ "}",
100
+ ].join("\n");
101
+ const at = await block(source, 7);
102
+ expect(at.start).toBe(2);
103
+ expect(at.tags.map((t) => t.text)).toEqual(["# colspan=6"]);
104
+ expect(at.tags.map((t) => t.line)).toEqual([6]);
105
+ expect(at.prose).toEqual([2, 3, 4, 5]);
106
+ });
107
+
108
+ it("starts a markdown block at its own opener, not at a body line that begins `#|`", async () => {
109
+ const source = [
110
+ "source: s is a extend {",
111
+ " dimension: d is 1",
112
+ " #|(markdown)",
113
+ " Notes",
114
+ "",
115
+ " #| a body line",
116
+ " |#",
117
+ " # colspan=6",
118
+ " view: v is x",
119
+ "}",
120
+ ].join("\n");
121
+ const at = await block(source, 8);
122
+ expect(at.start).toBe(2);
123
+ expect(at.prose).toEqual([2, 3, 4, 5, 6]);
124
+ });
125
+
126
+ it("does not call `#(markdown)` text inside a block comment prose", async () => {
127
+ const source = [
128
+ "source: s is a extend {",
129
+ "",
130
+ " /*",
131
+ " #(markdown) only a comment",
132
+ " */",
133
+ " # colspan=6",
134
+ " view: v is x",
135
+ "}",
136
+ ].join("\n");
137
+ const at = await block(source, 6);
138
+ expect(at.start).toBe(2);
139
+ expect(at.prose).toEqual([]);
140
+ });
141
+
89
142
  it("does not collect a `#` line written inside a block comment", async () => {
90
143
  const source = [
91
144
  "source: s is a extend {",
@@ -134,6 +187,132 @@ describe("blockAbove", () => {
134
187
  });
135
188
 
136
189
  describe("readDashboardDocument", () => {
190
+ it("reads a width spelled only as the dashboard_columns alias", async () => {
191
+ const doc = await read(
192
+ SIMPLE.replace(
193
+ '"a -> by_cat"] givens { CATEGORY="Jeans" } } dashboard { columns=12 }',
194
+ '"a -> by_cat"] givens { CATEGORY="Jeans" } dashboard_columns=8 }',
195
+ ),
196
+ );
197
+ expect(doc.columns).toBe(8);
198
+ });
199
+
200
+ describe("a width written badly", () => {
201
+ const withTag = (tagLine: string) =>
202
+ SIMPLE.replace(/^## artifact.*$/m, tagLine);
203
+
204
+ it("lets a written columns win even when it is not a width", async () => {
205
+ const doc = await read(
206
+ withTag(
207
+ '## artifact { tiles=["a -> by_cat"] dashboard_columns=8 } dashboard { columns=1.5 }',
208
+ ),
209
+ );
210
+ expect(doc.columns).toBeUndefined();
211
+ });
212
+
213
+ it("reads the alias, spaced round its =, when no columns is written", async () => {
214
+ const doc = await read(
215
+ withTag(
216
+ '## artifact { tiles=["a -> by_cat"] dashboard_columns = 8 }',
217
+ ),
218
+ );
219
+ expect(doc.columns).toBe(8);
220
+ });
221
+
222
+ it("takes text that only begins with digits as no width", async () => {
223
+ const doc = await read(
224
+ withTag(
225
+ '## artifact { tiles=["a -> by_cat"] dashboard_columns=8px }',
226
+ ),
227
+ );
228
+ expect(doc.columns).toBeUndefined();
229
+ });
230
+ });
231
+
232
+ describe("the description, by the server's rule", () => {
233
+ const rest = SIMPLE.split("\n").slice(5).join("\n");
234
+ const ARTIFACT = '## artifact { title="Probe" tiles=["a -> by_cat"] }';
235
+
236
+ it("reads the notes above the tag and ignores those below", async () => {
237
+ const doc = await read(`##" Above\n${ARTIFACT}\n##" Below\n${rest}`);
238
+ expect(doc.description).toBe("Above");
239
+ });
240
+
241
+ it("falls back to the notes below the tag when nothing above has prose", async () => {
242
+ const doc = await read(
243
+ `##"\n${ARTIFACT}\n##" Legacy\n##" text\n${rest}`,
244
+ );
245
+ expect(doc.description).toBe("Legacy\ntext");
246
+ });
247
+
248
+ it("finds the tag past a note whose prose says artifact", async () => {
249
+ const doc = await read(
250
+ `##" This artifact shows revenue\n${ARTIFACT}\n${rest}`,
251
+ );
252
+ expect(doc.description).toBe("This artifact shows revenue");
253
+ expect(doc.title).toBe("Probe");
254
+ });
255
+
256
+ it('reads a ##|" block above the tag, not the note below it', async () => {
257
+ const doc = await read(
258
+ `##|"\nBlock prose\n|##\n${ARTIFACT}\n##" Legacy\n${rest}`,
259
+ );
260
+ expect(doc.description).toBe("Block prose");
261
+ });
262
+
263
+ it('does not count an empty ##|" block above the tag as prose', async () => {
264
+ const doc = await read(`##|"\n|##\n${ARTIFACT}\n##" Legacy\n${rest}`);
265
+ expect(doc.description).toBe("Legacy");
266
+ });
267
+
268
+ it("does not take an artifact line inside a block for the tag", async () => {
269
+ const doc = await read(
270
+ `##|(text) intro\n## artifact { title="Fake" tiles=["x -> y"] }\n|##\n##" Above\n${ARTIFACT}\n${rest}`,
271
+ );
272
+ expect(doc.title).toBe("Probe");
273
+ expect(doc.description).toBe("Above");
274
+ });
275
+
276
+ it("ends a block only at a closer in the opener's column", async () => {
277
+ const doc = await read(
278
+ `##|"\nBlock prose\n |##\nstill inside\n|##\n${ARTIFACT}\n${rest}`,
279
+ );
280
+ expect(doc.description).toBe("Block prose\n|##\nstill inside");
281
+ });
282
+
283
+ it('takes a ##|" block below the tag as the fallback description, like the server', async () => {
284
+ const doc = await read(`${ARTIFACT}\n##|"\nBelow block\n|##\n${rest}`);
285
+ expect(doc.description).toBe("Below block");
286
+ });
287
+
288
+ it('ignores a ##" line inside a block', async () => {
289
+ const doc = await read(
290
+ `##|(text) intro\n##" not a note\n|##\n${ARTIFACT}\n${rest}`,
291
+ );
292
+ expect(doc.description).toBeUndefined();
293
+ });
294
+
295
+ it("reads neither a ##(markdown) line nor a ##|(markdown) block as the description or the tag", async () => {
296
+ const doc = await read(
297
+ `##(markdown) not a note\n##|(markdown) intro\n## How to read\n##" also not a note\n|##\n##" Above\n${ARTIFACT}\n##(markdown) nor this\n${rest}`,
298
+ );
299
+ expect(doc.description).toBe("Above");
300
+ expect(doc.title).toBe("Probe");
301
+ });
302
+
303
+ it("falls back to a note below the tag past a ##(markdown) line", async () => {
304
+ const doc = await read(
305
+ `##(markdown) skip\n${ARTIFACT}\n##(markdown) skip too\n##" Legacy\n${rest}`,
306
+ );
307
+ expect(doc.description).toBe("Legacy");
308
+ });
309
+
310
+ it("has no description when the only note is a malformed route", async () => {
311
+ const doc = await read(`##"word\n${ARTIFACT}\n${rest}`);
312
+ expect(doc.description).toBeUndefined();
313
+ });
314
+ });
315
+
137
316
  it("reads the whole shape", async () => {
138
317
  const doc = await read(SIMPLE);
139
318
  expect(doc.title).toBe("Probe");
@@ -630,7 +809,7 @@ describe("every composite dashboard in the repository opens", () => {
630
809
  const name = path.relative(REPO, file);
631
810
  // The lint fixtures exist to BE broken; they are exercised by the refusal
632
811
  // tests above rather than expected to open.
633
- const expectBroken = name.includes("dashboards-lint");
812
+ const expectBroken = /-lint[\\/]/.test(name);
634
813
  it(`${expectBroken ? "refuses" : "opens"} ${name}`, async () => {
635
814
  const result = await readDashboardDocument(
636
815
  fs.readFileSync(file, "utf8"),