Skip to content

test: add HTTP request regression snapshots - #290

Draft
penalosa wants to merge 14 commits into
mainfrom
penalosa/regression-testing
Draft

penalosa wants to merge 14 commits into
mainfrom
penalosa/regression-testing

Conversation

@penalosa

@penalosa penalosa commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a dedicated Vitest + MSW regression suite that runs the real cf CLI for every generated API command and snapshots its HTTP requests. Each command must reach its declared HTTP method and endpoint before its baseline can be accepted.

The current catalogue covers 2,952 generated commands and 1,169 command groups across 69,280 argument cases. Cases cover no arguments, required values, individual flags, enum and boolean values, pairwise flag presence, positional alternatives, command and option aliases, global options, local mode, body inputs, and uploads. Snapshots preserve method, URL, headers, JSON/binary bodies, and ordered multipart parts, with deterministic normalization for runtime and fixture details.

All commands listed in hand-written-commands.json and their exclusive groups remain excluded: local projects, external tools, and multi-request workflows need separate fixtures outside this suite's scope. Mock responses are empty success envelopes apart from zone-name lookup. Local request rewriting stays real, with Miniflare dispatch routed through MSW.

The regression task regenerates commands before testing. Twelve balanced test files run in twelve Linux GitHub Actions jobs; the small harness suite runs with the normal cross-platform CLI tests. Snapshots are marked as generated, and obsolete baselines have been removed after rebasing onto current main.

Validation:

  • pnpm check
  • pnpm --filter cf test:regression --maxWorkers=4 — 4,121 tests
  • Focused harness tests — 12 tests
  • Audited all 4,121 snapshot files for catalogue coverage, endpoint reachability, origins, and obsolete baselines

Test and CI changes only; no changeset is required.

@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/cf@290

commit: 942d6a7

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

cf --help startup

mean stddev min max
PR 228.1 ms 2.6 ms 224.2 ms 233.1 ms
base 230.6 ms 3.8 ms 225.5 ms 237.6 ms

Δ (PR vs base): ↓ -2.5 ms (-1.1%)

Measured with hyperfine on ubuntu-latest (3 warmup runs, 20 timed runs). CI numbers carry ±a few ms of runner jitter; treat small deltas as noise.

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🤖 I've done a thorough review of your PR.

Adds a parallel MSW/Vitest snapshot suite that records request behavior for the generated and hand-written CLI command surface.

  1. Warning: cf tunnels run is hand-written and bypasses the generic generated-command endpoint assertion. It performs /cfd_tunnel lookup requests, but is absent from workflowRequestPaths, so that request can silently disappear when its snapshot is updated.
"cf tunnels run": "/cfd_tunnel",
"cf tunnels tail": "/management",
  1. Warning: The workflow assertion only checks a path substring, so it accepts prerequisite reads in place of the primary mutation. Preview deploy's GET .../deployments/latest passes in place of its POST .../deployments, and image deletion's HEAD passes in place of DELETE.
const workflowPath = workflowRequestPaths[command.command];
const workflowMethod =
  command.command === "cf previews deploy"
    ? "POST"
    : command.command === "cf containers images delete"
      ? "DELETE"
      : undefined;
if (workflowPath) {
  expect(
    recordings.some((recording) =>
      recording.requests.some(
        (request) =>
          (!workflowMethod || request.method === workflowMethod) &&
          new URL(request.url).pathname.includes(workflowPath)
      )
    ),
    `${command.command} never reached ${workflowPath}. Fix its fixture before updating the request baseline.`
  ).toBe(true);
}

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🤖 I've done a thorough review of your PR.

Adds HTTP request regression snapshots across the CLI surface.

  1. Warning: cf tunnels run lacks workflow endpoint coverage.
  2. Warning: Path-only workflow checks can accept preflight requests instead of mutations.

github run

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

The workflow request guard has two gaps that let required hand-written API calls disappear when baselines are updated.

  1. cf tunnels run is hand-written and bypasses the generated-command endpoint assertion. When no token is supplied it resolves the tunnel through GET /cfd_tunnel, but workflowRequestPaths does not require that request. Store an expected method with each path and include this flow:
export const workflowRequestPaths: Record<
	string,
	{ path: string; method: string }
> = {
	"cf ai run": { path: "/ai/run", method: "POST" },
	"cf docs search": { path: "/api/ai-search/search", method: "POST" },
	"cf registrar registrations create": {
		path: "/registrar/registrations",
		method: "POST",
	},
	"cf workers versions create": { path: "/versions", method: "POST" },
	"cf workers triggers deploy": { path: "/schedules", method: "PUT" },
	"cf previews deploy": { path: "/deployments", method: "POST" },
	"cf containers images list": { path: "/_catalog", method: "GET" },
	"cf containers images delete": { path: "/manifests/", method: "DELETE" },
	"cf d1 migrations list": { path: "/query", method: "POST" },
	"cf d1 migrations apply": { path: "/query", method: "POST" },
	"cf tunnels run": { path: "/cfd_tunnel", method: "GET" },
	"cf tunnels tail": { path: "/management", method: "POST" },
};
  1. The suite checks only a pathname. Preview deploy records GET .../deployments/latest before its required POST .../deployments, and image deletion similarly sends HEAD before DELETE; dropping either mutation still satisfies the check. Require the mapped HTTP verb:
				const workflow = workflowRequestPaths[command.command];
				if (workflow) {
					expect(
						recordings.some((recording) =>
							recording.requests.some(
								(request) =>
									request.method === workflow.method &&
									new URL(request.url).pathname.includes(workflow.path)
							)
						),
						`${command.command} never reached ${workflow.method} ${workflow.path}. Fix its fixture before updating the request baseline.`
					).toBe(true);
				}

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Review: 2 findings.

🤖 I've done a thorough review of your PR.

Adds HTTP request regression snapshots and CI coverage.

  1. Warning: cf tunnels run lacks a required API endpoint guard.
  2. Warning: workflow guards check paths but not HTTP methods, allowing prerequisite requests to mask missing mutations.

Posted both fixes as GitHub suggestion comments.

github run

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

The workflow guard needs to check the expected HTTP method as well as the path. The preview snapshot records GET .../deployments/latest before the required POST .../deployments, and image deletion records HEAD .../manifests/... before DELETE; removing a mutation and updating its snapshot would still pass.

export const workflowRequestPaths: Record<
	string,
	{ path: string; method: string }
> = {
	"cf ai run": { path: "/ai/run", method: "POST" },
	"cf docs search": { path: "/api/ai-search/search", method: "POST" },
	"cf registrar registrations create": {
		path: "/registrar/registrations",
		method: "POST",
	},
	"cf workers versions create": { path: "/versions", method: "POST" },
	"cf workers triggers deploy": { path: "/schedules", method: "PUT" },
	"cf previews deploy": { path: "/deployments", method: "POST" },
	"cf containers images list": { path: "/_catalog", method: "GET" },
	"cf containers images delete": { path: "/manifests/", method: "DELETE" },
	"cf d1 migrations list": { path: "/query", method: "POST" },
	"cf d1 migrations apply": { path: "/query", method: "POST" },
};
const workflow = workflowRequestPaths[command.command];
if (workflow) {
	expect(
		recordings.some((recording) =>
			recording.requests.some(
				(request) =>
					request.method === workflow.method &&
					new URL(request.url).pathname.includes(workflow.path)
			)
		),
		`${command.command} never reached ${workflow.method} ${workflow.path}. Fix its fixture before updating the request baseline.`
	).toBe(true);
}

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🤖 I've done a thorough review of your PR.

Adds parallel MSW request snapshots and Linux CI coverage.

  1. Warning: Workflow guards accept prerequisite reads instead of required mutations. Posted a suggestion comment: test: add HTTP request regression snapshots #290 (comment)

github run

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

No new concerns since the last review

github run

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The suite claims alias coverage, but every included invocation uses canonical option names. In particular, cf containers images delete is exercised with --force but never its public -f alias, so a regression in that yargs alias or telemetry alias mapping can be accepted by updating this snapshot. Generate one equivalent case for each OptionMeta.alias (all alias forms are represented, and the current included surface has -f).

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🤖 I've done a thorough review of your PR.

Adds HTTP request regression snapshots and CI coverage.

  1. Warning: option aliases are not exercised. Posted a suggestion for alias cases, including cf containers images delete -f.

github run

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

No new concerns since the last review

github run

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@petebacondarwin
petebacondarwin force-pushed the penalosa/regression-testing branch from 26d71fc to a4127eb Compare November 4, 2026 14:02
Comment thread .github/workflows/regression.yml Fixed
@ask-bonk

ask-bonk Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

@ask-bonk

ask-bonk Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🤖 I've done a thorough review of your PR.

Adds generated-command HTTP request snapshots and sharded CI coverage.

  1. Warning: Global short aliases -q, -z, and -m lack regression cases. Posted an inline suggestion in cases.ts.

github run

@ask-bonk

ask-bonk Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

@petebacondarwin
petebacondarwin marked this pull request as ready for review November 4, 2026 14:27
@petebacondarwin
petebacondarwin marked this pull request as draft November 4, 2026 21:03
@petebacondarwin

Copy link
Copy Markdown
Collaborator

I am not convinced that these additional tests add much value on top of the effective snapshot which is the generated code. Do we really need to run 69,000 tests on every change?

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.

3 participants