Skip to content
52 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Artifacts contracts: folios, their four kinds, dashboard datasets, folio events and the artifacts scopes are typed and validated the same in TypeScript and Rust, with nothing using them yet1import assert from "node:assert/strict";
2import { readFileSync } from "node:fs";
3import { test } from "node:test";
4
5import { DATASETS, DATASET_IDS, datasetQueryError, datasetTime, parseDatasetQuery, type DatasetQuery } from "./datasets.ts";
6
7const fixtures = JSON.parse(readFileSync(new URL("./datasets.fixtures.json", import.meta.url), "utf8")) as {
8 cases: { query: unknown; error: string | null }[];
9};
10
11test("agrees with the Rust validator on every shared case", () => {
12 assert.ok(fixtures.cases.length > 20);
13 for (const { query, error } of fixtures.cases) {
14 const parsed = parseDatasetQuery(query);
15 const label = JSON.stringify(query);
16 if (error === null) assert.ok("query" in parsed, `${label}: ${"error" in parsed ? parsed.error : ""}`);
17 else if (error === "*") assert.ok("error" in parsed, `${label} should be refused`);
18 else assert.deepEqual(parsed, { error }, label);
19 }
20});
21
22test("a parsed query keeps only what the catalog knows", () => {
23 const parsed = parseDatasetQuery({ dataset: "issues", measure: { op: "count" }, sql: "DROP TABLE issues", group_by: "repo" });
24 assert.ok("query" in parsed);
25 assert.equal("sql" in parsed.query, false);
26 assert.equal(parsed.query.group_by, "repo");
27});
28
29test("every dataset has a time field and fields that are one thing each", () => {
30 assert.deepEqual(Object.keys(DATASETS), [...DATASET_IDS]);
31 for (const id of DATASET_IDS) {
32 const spec = DATASETS[id];
33 assert.ok(spec.times.length > 0, id);
34 for (const field of spec.dimensions) assert.ok(!spec.measures.includes(field) && !spec.rates.includes(field), `${id}.${field}`);
35 }
36 assert.equal(DATASETS.spend.needs, "billing");
37});
38
39test("a typed query is checked against the catalog", () => {
40 const ok: DatasetQuery = { dataset: "workflow_runs", measure: { op: "rate", field: "succeeded" }, interval: "day", range: "30d" };
41 assert.equal(datasetQueryError(ok), null);
42 assert.equal(datasetQueryError({ ...ok, limit: 2.5 }), "limit is between 1 and 100.");
43});
44
45test("range ends are real dates or UTC times", () => {
46 assert.equal(datasetTime("1970-01-02"), 86_400_000);
47 assert.equal(datasetTime("2026-10-02T05:16:19Z"), 1_790_918_179_000);
48 assert.equal(datasetTime("2026-10-02T05:16:19.5Z"), 1_790_918_179_500);
49 for (const bad of ["2026-02-29", "2026-04-31", "2026-13-01", "2026-10-02T24:00:00Z", "2026-10-02T05:16:19", "2026-10-02T05:16:19+02:00", "26-10-02", "2026-1-02", "today", ""]) {
50 assert.equal(datasetTime(bad), null, bad);
51 }
52});