MCPcopy
hub / github.com/coder/mux / runSampleQuery

Function runSampleQuery

src/browser/features/Analytics/SqlExplorer.test.ts:51–83  ·  view source on GitHub ↗
(sample: SampleQuery)

Source from the content-addressed store, hash-verified

49}
50
51function runSampleQuery(sample: SampleQuery): void {
52 assert(
53 typeof sample.label === "string" && sample.label.trim().length > 0,
54 "Sample query label must be a non-empty string"
55 );
56 assert(
57 typeof sample.sql === "string" && sample.sql.trim().length > 0,
58 "Sample query sql must be a non-empty string"
59 );
60
61 const payload: SampleQueryRunnerPayload = {
62 createEventsTableSql: CREATE_EVENTS_TABLE_SQL,
63 seedEventsRowSql: SEED_EVENTS_ROW_SQL,
64 sample,
65 };
66
67 // Bun cannot load @duckdb/node-api in this environment because the native
68 // binding depends on libstdc++. Run the DuckDB execution under Node while
69 // keeping the SQL setup and assertions in this test file.
70 const runner = spawnSync("node", [SAMPLE_QUERY_RUNNER_PATH], {
71 env: {
72 ...process.env,
73 [SAMPLE_QUERY_RUNNER_PAYLOAD_ENV]: JSON.stringify(payload),
74 },
75 encoding: "utf8",
76 });
77
78 const output = `${runner.stdout ?? ""}${runner.stderr ?? ""}`.trim();
79 assert(
80 runner.status === 0,
81 output.length > 0 ? output : `Sample query "${sample.label}" failed without diagnostic output`
82 );
83}
84
85describe("SAMPLE_QUERIES", () => {
86 for (const sample of SAMPLE_QUERIES) {

Callers 1

Calls 1

assertFunction · 0.50

Tested by

no test coverage detected