codeant-ai-for-open-source[bot] commented on code in PR #43303:
URL: https://github.com/apache/superset/pull/43303#discussion_r3805047503


##########
superset-frontend/scripts/gen-qc-fixtures.mjs:
##########
@@ -0,0 +1,108 @@
+// Generates a minimal-but-valid form_data fixture + frontend golden for every 
viz
+// type in the generated REGISTRY, by actually running each plugin's 
buildQuery under
+// Node's V8. A viz is COVERED if its builder returns a real query_context on 
the base
+// form_data; otherwise it's honestly SKIPPED (reason recorded) โ€” never faked.
+import { build } from 'esbuild';
+import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
+import { createRequire } from 'node:module';
+
+const require = createRequire(import.meta.url);
+const FEX = 'src/backend-querycontext/__fixtures__';
+
+const res = await build({
+  entryPoints: ['src/backend-querycontext/entry.ts'],
+  bundle: true,
+  format: 'cjs',
+  platform: 'node',
+  target: 'es2020',
+  write: false,
+  legalComments: 'none',
+});
+const shim = (k, v) => {
+  try {
+    if (globalThis[k] === undefined) globalThis[k] = v;
+  } catch {
+    /* read-only builtin */
+  }
+};
+shim('self', globalThis);
+shim('window', globalThis);
+shim('navigator', { userAgent: 'superset-fixtures-node' });
+shim('document', {});
+const mod = { exports: {} };
+new Function('module', 'exports', 'require', res.outputFiles[0].text)(mod, 
mod.exports, require);
+const gen = mod.exports.generateQueryContext;
+const VIZ_TYPES = mod.exports.VIZ_TYPES || globalThis.SUPERSET_QC_VIZ_TYPES;
+
+// A deliberately broad base form_data โ€” each plugin's buildQuery reads the 
fields it
+// needs and ignores the rest. Family-specific fields are all populated so most
+// builders find what they require without per-viz hand-tuning.
+const baseFor = (viz) => ({
+  datasource: '1__table',
+  viz_type: viz,
+  metric: 'count',
+  metrics: ['count'],
+  groupby: ['gender'],
+  columns: ['gender'],
+  all_columns: ['gender', 'name'],
+  entity: 'gender',
+  series: 'gender',
+  series_columns: ['gender'],
+  x_axis: 'ds',
+  granularity_sqla: 'ds',
+  time_grain_sqla: 'P1D',
+  time_range: 'No filter',
+  row_limit: 100,
+  adhoc_filters: [],
+  // graph/sankey/tree
+  source: 'gender',
+  target: 'name',
+  source_category: 'gender',
+  target_category: 'name',
+  // heatmap
+  x_axis_column: 'gender',
+  y_axis: 'name',
+  // bubble
+  x: 'count',
+  y: 'count',
+  size: 'count',
+  // histogram
+  column: 'num',
+  // mixed timeseries second query
+  metrics_b: ['count'],
+  groupby_b: ['gender'],
+  adhoc_filters_b: [],
+});
+
+mkdirSync(`${FEX}/formdata`, { recursive: true });
+mkdirSync(`${FEX}/expected`, { recursive: true });
+
+const covered = [];
+const skipped = [];
+for (const viz of VIZ_TYPES) {
+  const fd = baseFor(viz);
+  let out;
+  try {
+    out = JSON.parse(gen(viz, JSON.stringify(fd)));
+  } catch (e) {
+    skipped.push([viz, `threw: ${String(e).slice(0, 120)}`]);
+    continue;
+  }
+  if (!out || out.__unsupported__ || out.__error__) {
+    skipped.push([viz, out && out.__error__ ? `builder error: 
${String(out.__error__).slice(0, 140)}` : 'unsupported']);
+    continue;
+  }
+  if (!Array.isArray(out.queries) || out.queries.length === 0) {
+    skipped.push([viz, 'no queries produced']);
+    continue;
+  }
+  writeFileSync(`${FEX}/formdata/${viz}.json`, JSON.stringify(fd, null, 2) + 
'\n');
+  writeFileSync(`${FEX}/expected/${viz}.json`, JSON.stringify(out, null, 2) + 
'\n');
+  covered.push(viz);

Review Comment:
   **Suggestion:** The generator only writes fixtures for currently covered viz 
types and never removes existing fixture files. After a viz type is removed 
from the registry or becomes skipped, its stale form-data fixture remains, so 
the parity test still loads it and fails the `VIZ_TYPES` membership check or 
compares an obsolete golden. Clear or reconcile both fixture directories before 
generating the new set. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Minor ๐Ÿงน</summary>
   
   ```mdx
   - โš ๏ธ Registry changes can leave obsolete parity fixtures behind.
   - โš ๏ธ Frontend parity tests fail until stale files are manually removed.
   - โš ๏ธ Fixture regeneration does not produce a reliable synchronized set.
   ```
   </details>
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://github.com/CodeAnt-AI/skills/blob/main/skills/codeant-resolve-pr-comments/SKILL.md)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/scripts/gen-qc-fixtures.mjs
   **Line:** 82:101
   **Comment:**
        *Logic Error: The generator only writes fixtures for currently covered 
viz types and never removes existing fixture files. After a viz type is removed 
from the registry or becomes skipped, its stale form-data fixture remains, so 
the parity test still loads it and fails the `VIZ_TYPES` membership check or 
compares an obsolete golden. Clear or reconcile both fixture directories before 
generating the new set.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43303&comment_hash=cd35dd883cc7c6b8aeec98891afab24f26acc49cc156792da5a5676d99f49c5f&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43303&comment_hash=cd35dd883cc7c6b8aeec98891afab24f26acc49cc156792da5a5676d99f49c5f&reaction=dislike'>๐Ÿ‘Ž</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to