Skip to content

tests: Unflake and fix dataflow visualizer - #38359

Merged
def- merged 1 commit into
MaterializeInc:mainfrom
def-:pr-unflake-dataflow-visualizer
Aug 19, 2026
Merged

def- merged 1 commit into
MaterializeInc:mainfrom
def-:pr-unflake-dataflow-visualizer

Conversation

@def-

@def- def- commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

@def-
def- requested a review from antiguru August 19, 2026 16:55
@def-
def- requested a review from a team as a code owner August 19, 2026 16:55
@def-
def- force-pushed the pr-unflake-dataflow-visualizer branch from dd216ef to 40d09b9 Compare August 19, 2026 17:12

@antiguru antiguru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The direction is right: pinning the tests to a fixture dataflow instead of "whatever sorts first" removes a real source of flakiness, and dropping the test.skip-on-DDL-failure dance in favour of setting the fixture up over pgwire is a clear improvement. The comments explaining why each choice is load-bearing are genuinely useful.

One blocker plus a few things worth folding in before merge. Inline comments have the detail; summarising here.

Blocker

test/dataflow-visualizer/tests/fixture.ts is missing from the branch. Both spec files import FIXTURE_CLUSTER/FIXTURE_REPLICA/FIXTURE_INDEX/FIXTURE_DATAFLOW/fixturePage from ./fixture, so as it stands Playwright can't load either file. Details inline on memory.spec.ts.

Should fix

  • Step timeout headroom. workers: 1 plus a 3x per-test timeout, against timeout_in_minutes: 30. Inline on playwright.config.ts.
  • The step doesn't run on visualizer changes. inputs: [test/dataflow-visualizer] (ci/test/pipeline.template.yml:835) doesn't cover src/environmentd/src/http/static/js. This PR changes production JSX that the new tests now assert on, but a future JSX-only change skips the suite entirely, which undercuts the coverage being built here. Adding the static js directory to inputs would make it load-bearing.
  • create_fixture_dataflow is no longer idempotent. Inline on mzcompose.py.

Worth considering

  • ClusterReplicaView is now duplicated verbatim across memory.jsx and hierarchical-memory.jsx, new comment block and all. There's already a shared fetch.js; hoisting this into a shared cluster-replica.jsx would stop the copy growing. Happy for this to be a follow-up.
  • hierarchical-memory.spec.ts's page renders without crashing after data load still does waitForTimeout(3000) then not.toContainText('error:'), which passes vacuously while the page is still showing Loading.... Same class of weakness as the ones fixed in memory.spec.ts, and now that the page defaults to quickstart it's cheap to wait for the real render instead.
  • The "dataflows reporting none sort first" comment (both mzcompose.py and memory.spec.ts) is correct, but only because records is nullable in mz_records_per_dataflow and ORDER BY records DESC is NULLS FIRST. "Reporting none" reads like zero, which would sort last. Naming the NULL would make the comment stand on its own.
  • const [session_cluster_table, replicas_table] = data.results; followed by sessionCluster mixes conventions within three lines. Views uses records_table, so snake_case is locally consistent; it's just the mix that reads oddly.
  • with c.sql_cursor(...) closes the cursor but leaks the connection, since reuse_connection defaults to False.

Pre-existing bug, for a follow-up

Noticed while reading hierarchical-memory.jsx. getCreateView(stats.name) (line 178) reads stats, which is useState(null) and never assigned, so it always throws a TypeError that the surrounding try/catch swallows into a console.debug. And getCreateView itself reads view_name_table.rows and create_table.rows[0][0], but query() returns {results: [...]} — so the SHOW CREATE VIEW panel on that page has never worked. Out of scope for an unflaking PR, but it's the largest actual defect in a file this one is titled as fixing, so it seemed worth recording.


Generated by Claude Code

Comment on lines +11 to +16
import {
FIXTURE_CLUSTER,
FIXTURE_DATAFLOW,
FIXTURE_REPLICA,
fixturePage,
} from './fixture';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker: tests/fixture.ts isn't in the branch. Listing test/dataflow-visualizer/tests/ at dd216ef gives only the four *.spec.ts files, and the diff's six changed files are all accounted for elsewhere. So both this file and hierarchical-memory.spec.ts fail module resolution and all 12 of their tests error out instead of running.

Worth noting it won't be caught before the mzcompose step either: ci/test/lint-main/checks/check-js-typedefs.sh typechecks only the three files listed in tsconfig.typecheck.json (prometheus.js, metrics.jsx, fetch.js), not the specs.

Two things to watch when adding it:

  • FIXTURE_DATAFLOW has no counterpart in the service environment list in mzcompose.py (only FIXTURE_CLUSTER, FIXTURE_REPLICA, FIXTURE_INDEX are passed), so it has to be derived, and the derivation needs the Dataflow: materialize.public. prefix from somewhere.
  • A fallback for the env vars would keep npx playwright test usable outside the composition.

Generated by Claude Code

Comment on lines +15 to 20
// behind the visualizer are unindexed scans. Two workers on a CI agent turn
// those into multi-second waits that trip the assertion timeouts below, so
// pin the suite to a single worker rather than only serializing each file.
fullyParallel: false,
workers: 1,
retries: 1,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workers: 1 plus the per-test timeout going 30s to 90s, across ~34 tests with retries: 1, runs against timeout_in_minutes: 30 on the Buildkite step (ci/test/pipeline.template.yml:834). Before this, fullyParallel: false still let the four spec files run concurrently, so on the 4cpu agent the suite was effectively 4-way parallel; serializing it multiplies wall clock at the same time as the timeout budget per test triples.

A step timeout is exactly the opaque failure this PR is trying to remove, so it'd be worth raising timeout_in_minutes in the same commit.

Separately, LOAD_TIMEOUT in memory.spec.ts is doing what a config-level expect: { timeout: ... } would do for the whole suite. hierarchical-memory.spec.ts still hardcodes its own 20000s in three places.


Generated by Claude Code

Comment on lines +86 to +89
c.sql(f"""
CREATE TABLE {FIXTURE_TABLE} (id int, other int);
CREATE INDEX {FIXTURE_INDEX} IN CLUSTER {FIXTURE_CLUSTER} ON {FIXTURE_TABLE} (id);
INSERT INTO {FIXTURE_TABLE} VALUES (1, 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DDL this replaces used IF NOT EXISTS, and dropping that makes the workflow non-idempotent: re-running it against an already-up composition (without down -v) now fails on "table already exists" before any test runs. Cheap to restore, and then the INSERT just adds a second row, which none of the assertions care about.


Generated by Claude Code

Comment on lines +27 to +33
// The first statement decides which replica to show when the URL names none.
// Ask the session for its cluster rather than naming one here: the built-in
// default has been renamed before, and a name hardcoded in this file that
// stops matching fails silently, leaving the page on whichever replica
// happens to sort first.
const queryClusterReplicas = `
SELECT current_setting('cluster');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design question rather than a bug. In a real deployment the internal port is reached through a proxy that injects x-materialize-user: mz_support (src/environmentd/src/http.rs:781), and mz_support's default cluster is mz_catalog_server (INTERNAL_USER_NAME_TO_DEFAULT_CLUSTER, src/sql/src/session/user.rs:52). So for the users who actually open this page, current_setting('cluster') resolves to exactly the expensive builtin cluster the new comment describes as "not what a user opening this page came to look at". Under test the user is anonymous_http_user, whose cluster is the system default quickstart, which is why the new assertion passes.

Not a regression: the old default/r1 preference never matched a modern bootstrap, so it already fell through to results[0], which is mz_catalog_server under ORDER BY cluster_name. But the stated benefit only materializes for anonymous sessions. If the intent is "prefer a user cluster", it might be worth encoding that directly: session cluster, then first non-system cluster, then first replica.

Two things I checked so you don't have to:

  • The two-statement simple request is safe. current_setting plans through UnmaterializableFunc::ViewableVariables and folds to a constant, so the first statement pins no timestamp, timedomain_for gets an empty id set, and no read holds are stored. The second statement is then free to establish the timedomain, so no RelationOutsideTimeDomain. Views below already relies on multi-statement requests anyway.
  • The new test's #cluster_replica assertion does discriminate, since quickstart sorts after every mz_* cluster.

Minor: "Rows are ordered by replica name" undersells it. The query orders by cluster_name ASC, replica_name ASC, and it's the cluster ordering that decides what results[0] is.


Generated by Claude Code

@def-
def- force-pushed the pr-unflake-dataflow-visualizer branch from 40d09b9 to a619221 Compare August 19, 2026 20:29
@def-

def- commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, fixed up, except for the sleep timeout (already way below the 30 min) and inputs already covers the static js.

@def-
def- requested a review from antiguru August 19, 2026 20:31

@antiguru antiguru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All addressed, thanks. Extracting the picker into cluster-replica.jsx and preferring a user cluster over the session's own is a better answer than what I suggested, and fixing getCreateView for real (plus indexing a view so the lookup resolves, plus a test for it) turns the pre-existing dead panel into working code. Widening tsconfig.typecheck.json to the specs is the part that keeps this from regressing.

Verified locally: npm install --prefix test/dataflow-visualizer && tsc -p test/dataflow-visualizer/tsconfig.typecheck.json is clean, and the new cluster-replica.jsx needs no registration since handle_static uses include_dir! over the whole directory.

One nit, take it or leave it: replicaPage in tests/fixture.ts is exported but only called by fixturePage two lines below it.


Generated by Claude Code

@def-
def- enabled auto-merge (squash) August 19, 2026 20:41
@def-
def- merged commit 653daf7 into MaterializeInc:main Aug 19, 2026
76 checks passed
@def-
def- deleted the pr-unflake-dataflow-visualizer branch August 19, 2026 20:56
@def-

def- commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor Author

QA LLM Review (Post Merge)

@def- — an automated review of commit 653daf7b5f found the following potential MEDIUM+ issue(s) after this PR was merged.

1. HIGH -- Fixing getCreateView activates a stored SQL injection through catalog object names

src/environmentd/src/http/static/js/memory.jsx:646

Unwrapping the /api/sql envelope makes getCreateView reach its second query for the first time, and that query interpolates a catalog-derived view name straight into SHOW CREATE VIEW "..." with no identifier escaping. A view name containing a double quote lets any principal with CREATE on a schema plant SQL that later executes in the session of whoever opens /memory and expands that dataflow, with that viewer's privileges.

Details

Before this commit const view_name_table = await query(...) read .rows off the {results: [...]} envelope, so getCreateView always threw a TypeError before line 646 and the SHOW CREATE VIEW was dead code. Line 605 now destructures results, so both queries run.

Attack: create a benign view realview, then create CREATE VIEW "realview""; <payload>; SELECT """ AS ... and an index on it. mz_records_per_dataflow reports the dataflow as Dataflow: materialize.public.<index>; the first query resolves the index back to the evil view name; line 646 then emits

SHOW CREATE VIEW "materialize"."public"."realview"; <payload>; SELECT ""

/api/sql executes a simple-query batch statement by statement (src/environmentd/src/http/sql.rs:1386), so statement 1 succeeds against the decoy view, the payload runs, and the trailing fragment fails. View's try/catch swallows that failure into console.debug('could not get create view'), so the viewer just sees a graph with no View: block.

The base route group, which owns /memory and /api/sql, is enabled for normal roles on the external listener (src/environmentd/src/http.rs:300-304), so the victim can be an org admin or superuser; on the internal listener it is mz_support reached through the support proxy. Expanding the largest dataflow is the page's primary interaction and the attacker controls how large their dataflow is.

Fix: quote the identifiers.

+function quoteIdent(ident) {
+  return `"${ident.replace(/"/g, '""')}"`;
+}
+
 async function getCreateView(dataflow_name) {
@@
-  } = await query(`SHOW CREATE VIEW "${name[0]}"."${name[1]}"."${name[2]}"`);
+  } = await query(
+    `SHOW CREATE VIEW ${quoteIdent(name[0])}.${quoteIdent(name[1])}.${quoteIdent(name[2])}`
+  );

The '${match[N]}' interpolations at lines 631-633 need the equivalent literal escaping (s.replace(/'/g, "''")). Note that formatNameForQuery in this file is not reusable for that: it passes a string, not a regex, to String.replace, so it only escapes the first quote in a name.

def- added a commit that referenced this pull request Aug 20, 2026
The /memory page resolves an expanded dataflow back to the view its
index was built on, and interpolated both the index name it parses out
of the dataflow name and the view name that lookup returns straight into
the statements it sends to /api/sql. Those names are chosen by whoever
created the object, and the statements run in the session of whoever
opened the page, so a catalog name carrying a quote could run SQL with
the viewer's privileges.

The escaper the pages already had for cluster and replica names passed a
string rather than a regex to String.replace, so it escaped only the
first quote of a name, which is no escaping at all for a name carrying
two. Those two names come straight from URL parameters, as does the
dataflow id, which is interpolated as a number and so cannot be made
safe by quoting at all, and is now rejected unless it is an integer.

Both pages now quote through sqlLiteral and sqlIdent in fetch.js, which
they already share for the /api/sql call itself, and a browser test pins
that both helpers escape every quote rather than just the first.

Found via the QA LLM review, sorry for only catching it after the PR
merged:
#38359 (comment)

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants