@@ -41,6 +41,40 @@ test("retains results on an error and exports", async ({ page }) => {
|
||||
await page.getByRole("button", { name: "JSON", exact: true }).click();
|
||||
expect((await pending).suggestedFilename()).toBe("query-result.json");
|
||||
});
|
||||
test("runs the locally bundled bounded DuckDB worker in Chromium", async ({
|
||||
page,
|
||||
browserName,
|
||||
request,
|
||||
}) => {
|
||||
test.skip(browserName !== "chromium", "Targeted DuckDB-WASM Chromium flow");
|
||||
const external = await local(page);
|
||||
await page.goto("/deep/nested/query/");
|
||||
await page.getByLabel("Execution engine").selectOption("duckdb-wasm");
|
||||
await page
|
||||
.getByRole("textbox", { name: "Query", exact: true })
|
||||
.fill(
|
||||
"SELECT team, avg(score) AS average FROM data GROUP BY team ORDER BY team",
|
||||
);
|
||||
const wasmResponse = page.waitForResponse((response) =>
|
||||
response.url().endsWith(".wasm"),
|
||||
);
|
||||
await page.getByRole("button", { name: "Run query" }).click();
|
||||
await expect(page.getByRole("status")).toContainText(
|
||||
"returned 2 result rows",
|
||||
{
|
||||
timeout: 60_000,
|
||||
},
|
||||
);
|
||||
await expect(page.getByRole("cell", { name: "blue" })).toBeVisible();
|
||||
const wasmUrl = (await wasmResponse).url();
|
||||
const wasm = await request.get(wasmUrl);
|
||||
expect(wasm.headers()["content-type"]).toBe("application/wasm");
|
||||
expect(wasm.headers()["cache-control"]).toContain("immutable");
|
||||
expect(wasm.headers()["content-security-policy"]).toContain(
|
||||
"'wasm-unsafe-eval'",
|
||||
);
|
||||
expect(external).toEqual([]);
|
||||
});
|
||||
test("shell PWA headers, offline reload, and theme", async ({
|
||||
page,
|
||||
context,
|
||||
@@ -76,6 +110,6 @@ test("shell PWA headers, offline reload, and theme", async ({
|
||||
const manifest = await request.get("/deep/nested/query/toolbox-app.json");
|
||||
await expect(manifest.json()).resolves.toMatchObject({
|
||||
id: "de.add-ideas.query-tools",
|
||||
version: "0.1.0",
|
||||
version: "0.2.0",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("keeps the primary workspace inside a narrow viewport", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/deep/nested/query/");
|
||||
await expect(page.locator("main").first()).toBeVisible();
|
||||
await expect(
|
||||
page.locator("main .loading, main .workbench-loading"),
|
||||
).toHaveCount(0);
|
||||
|
||||
const widths = await page.evaluate(() => ({
|
||||
content: document.documentElement.scrollWidth,
|
||||
viewport: document.documentElement.clientWidth,
|
||||
}));
|
||||
expect(widths.viewport).toBeLessThanOrEqual(430);
|
||||
expect(widths.content).toBeLessThanOrEqual(widths.viewport + 1);
|
||||
});
|
||||
+36
-1
@@ -2,12 +2,47 @@ import { describe, expect, it } from "vitest";
|
||||
import { parseData } from "../../src/core/data";
|
||||
describe("data parser", () => {
|
||||
it("parses CSV inference and NDJSON", () => {
|
||||
expect(parseData("name,n\nAda,3", "csv").rows[0]).toEqual({
|
||||
const csv = parseData("name,n\nAda,3", "csv");
|
||||
expect(csv.rows[0]).toEqual({
|
||||
name: "Ada",
|
||||
n: 3,
|
||||
});
|
||||
expect(csv.evidence.csv).toMatchObject({
|
||||
rawRows: [["Ada", "3"]],
|
||||
cells: expect.arrayContaining([
|
||||
expect.objectContaining({ field: "n", raw: "3", inferred: "number" }),
|
||||
]),
|
||||
});
|
||||
expect(parseData('{"a":1}\n{"a":2}', "ndjson").rows).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("makes inference explicit and preserves unsafe-number evidence", () => {
|
||||
expect(
|
||||
parseData("id,empty\n9007199254740993,null", "csv", {
|
||||
csvInference: "safe",
|
||||
inferNulls: false,
|
||||
}).rows[0],
|
||||
).toEqual({ id: "9007199254740993", empty: "null" });
|
||||
const json = parseData(
|
||||
'{"id":9007199254740993,"decimal":0.12345678901234567,"exact":"9007199254740993"}',
|
||||
"json",
|
||||
);
|
||||
expect(json.evidence.jsonNumbers).toEqual([
|
||||
expect.objectContaining({
|
||||
raw: "9007199254740993",
|
||||
risk: "unsafe-integer",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
raw: "0.12345678901234567",
|
||||
risk: "precision-risk",
|
||||
}),
|
||||
]);
|
||||
expect(() =>
|
||||
parseData('{"id":9007199254740993}', "json", {
|
||||
rejectUnsafeJsonNumbers: true,
|
||||
}),
|
||||
).toThrow(/precision risk/iu);
|
||||
});
|
||||
it("converts static XML and rejects entities", () => {
|
||||
expect(
|
||||
parseData(
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseDuckDbQuery } from "../../src/core/duckdb";
|
||||
|
||||
describe("DuckDB query boundary", () => {
|
||||
it("records a single SELECT token stream", () => {
|
||||
expect(
|
||||
parseDuckDbQuery("SELECT team, avg(score) FROM data GROUP BY team"),
|
||||
).toMatchObject({
|
||||
type: "duckdb-query",
|
||||
statement: "SELECT",
|
||||
tokens: expect.arrayContaining([
|
||||
{ kind: "word", value: "data", offset: 29 },
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
"INSTALL httpfs",
|
||||
"SELECT * FROM data; DROP TABLE data",
|
||||
"COPY data TO 'x.csv'",
|
||||
"PRAGMA version",
|
||||
])("rejects non-read-only statement %s", (source) => {
|
||||
expect(() => parseDuckDbQuery(source)).toThrow();
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseData } from "../../src/core/data";
|
||||
import { runQuery } from "../../src/core/query";
|
||||
import { parsePathQuery, parseSqlQuery, runQuery } from "../../src/core/query";
|
||||
describe("query engine", () => {
|
||||
const root = parseData(
|
||||
'[{"team":"a","n":2},{"team":"a","n":4},{"team":"b","n":9}]',
|
||||
@@ -32,4 +32,31 @@ describe("query engine", () => {
|
||||
/Unsupported path/iu,
|
||||
);
|
||||
});
|
||||
|
||||
it("exposes parsed SQL and path ASTs", () => {
|
||||
expect(
|
||||
parseSqlQuery(
|
||||
"SELECT team AS group_name WHERE n >= 2 ORDER BY n DESC LIMIT 4",
|
||||
),
|
||||
).toMatchObject({
|
||||
type: "sql-query",
|
||||
select: [{ type: "field", path: ["team"], alias: "group_name" }],
|
||||
where: [{ type: "condition", path: ["n"], operator: ">=", value: 2 }],
|
||||
orderBy: { path: ["n"], direction: "DESC" },
|
||||
limit: 4,
|
||||
});
|
||||
expect(parsePathQuery("$[*][?(@.n >= 4)].team").segments).toEqual([
|
||||
{ type: "wildcard" },
|
||||
{
|
||||
type: "filter",
|
||||
condition: {
|
||||
type: "condition",
|
||||
path: ["n"],
|
||||
operator: ">=",
|
||||
value: 4,
|
||||
},
|
||||
},
|
||||
{ type: "property", key: "team", quoted: false },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user