Skip to content

[cli] test: reproduce #6803 — codegen runs twice for codegen then codegen watch (failing) - #10948

Draft
eddeee888 wants to merge 1 commit into
masterfrom
claude/sweet-bardeen-oegxya
Draft

[cli] test: reproduce #6803 — codegen runs twice for codegen then codegen watch (failing)#10948
eddeee888 wants to merge 1 commit into
masterfrom
claude/sweet-bardeen-oegxya

Conversation

@eddeee888

@eddeee888 eddeee888 commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Description

This is a checkpoint PR, not a fix. It adds a failing test that proves the behavior reported in #6803 exists in the current code — it does not need to merge, or even go green, before a follow-up fix builds on top of it.

Relates to #6803

What #6803 reports: in the common workflow of running codegen once (to fail fast before compiling) and then codegen watch to keep types up to date while developing, codegen watch itself unconditionally runs a full codegen pass again before it starts watching for file changes — duplicating the run that was just done, with nothing having changed in between.

Confirmed directly in the source, not just from the issue text — packages/graphql-codegen-cli/src/utils/watcher.ts, createWatcher():

stopWatching.runningWatcher = new Promise<void>((resolve, reject) => {
  initialContext.profiler
    .run(() => executeCodegen(initialContext), 'executeCodegen') // <- always runs, unconditionally
    .then(...)
    .then(() => runWatcher(abortController.signal)) // <- only *then* does watching start
    ...

There is no existing option to skip this initial run.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Checkpoint: failing test proving the reported behavior (see issue-verify/issue-fix workflow below)

How Has This Been Tested?

Added a new test, Watch runs - duplicate initial run (#6803) in packages/graphql-codegen-cli/tests/watcher.run.spec.ts, that directly mirrors the reported workflow rather than any hypothetical fix API:

  1. Step 1 — a plain, non-watch generate() call against a schema/documents pair, standing in for the first codegen CLI invocation.
  2. Step 2 — a watcher started right after (createWatcher), against the same schema/documents with nothing changed on disk, standing in for the immediately-following codegen watch invocation.

It spies on executeCodegen and asserts the total call count across both steps is 1 (nothing changed, so a second full run is redundant).

Run: pnpm vitest run tests/watcher.run.spec.ts -t "duplicate initial run" inside packages/graphql-codegen-cli.

Captured failure (current behavior — codegen runs a second time regardless):

AssertionError: expected "executeCodegen" to be called 1 times, but got 2 times
 ❯ tests/watcher.run.spec.ts:1055:33
      expect(executeCodegenSpy).toHaveBeenCalledTimes(1);

This test is left failing on purpose — it's the checkpoint this PR exists to produce, not something to skip or mark pending.

Test Environment:

  • OS: Linux
  • @graphql-codegen/cli: workspace (unreleased)
  • NodeJS: 22

Checklist:

  • I have added tests that prove my fix is effective or that my feature works — a failing test proving the reported gap exists (the fix itself is out of scope for this PR)
  • New and existing unit tests pass locally with my changes — this one is expected to fail until a follow-up fix lands
  • I have performed a self-review of my own code

Further comments

This PR is produced by an issue-verify pass and is meant to be picked up directly by a follow-up issue-fix PR, which will implement an actual mechanism for watch mode to skip its redundant initial codegen run and turn this test green. The test intentionally avoids assuming any particular fix API/config shape — it only asserts on the observable symptom (executeCodegen call count).

🤖 Generated with Claude Code

https://claude.ai/code/session_019qAsujZbmFpSQmLQYQiq9Z

@changeset-bot

changeset-bot Bot commented Sep 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 29412b5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@eddeee888
eddeee888 force-pushed the claude/sweet-bardeen-oegxya branch from 09e3b0a to 56fd82b Compare September 12, 2026 12:16
@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-codegen/client-preset 6.2.0-alpha-20260912122715-29412b5e80207935265bf0239359fe4c78db476f npm ↗︎ unpkg ↗︎

…n watch`

Watch mode unconditionally runs a full codegen pass before it starts
watching for file changes (packages/graphql-codegen-cli/src/utils/watcher.ts,
`createWatcher`'s `runningWatcher` promise). There is currently no way to
opt out of that initial run.

This matters for the reported workflow: run `codegen` once (to fail fast
before compiling), then start `codegen watch` to keep types up to date.
Watch mode's own initial pass duplicates that just-completed run with
nothing having changed in between.

Adds a failing test that mirrors this exact workflow: a plain, non-watch
`generate()` call (step 1, standing in for the first `codegen` invocation),
immediately followed by starting a watcher against the same schema/documents
(step 2, standing in for `codegen watch`). It asserts `executeCodegen` was
called a total of once after both steps, since nothing changed between them.
It fails today because watch mode always runs its own initial pass
regardless — `executeCodegen` ends up called twice.

eddeee888:oss:issue-verify

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019qAsujZbmFpSQmLQYQiq9Z
@eddeee888
eddeee888 force-pushed the claude/sweet-bardeen-oegxya branch from 56fd82b to 29412b5 Compare September 12, 2026 12:26
@eddeee888 eddeee888 changed the title [cli] test: reproduce #6803 — codegen watch always runs an extra initial codegen (failing) [cli] test: reproduce #6803 — codegen runs twice for codegen then codegen watch (failing) Sep 12, 2026
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