Skip to content

Remove stale generated imports and improve sync validation#40

Merged
ruudk merged 2 commits intomainfrom
stale
Apr 18, 2026
Merged

Remove stale generated imports and improve sync validation#40
ruudk merged 2 commits intomainfrom
stale

Conversation

@ruudk
Copy link
Copy Markdown
Owner

@ruudk ruudk commented Apr 18, 2026

This PR improves code maintenance by automatically removing stale generated imports and enhances the developer experience by showing diffs when --ensure-sync detects mismatches, making it easier to understand and fix synchronization issues.

Introduce stale generated import removal

When a file is moved or refactored, the hash in generated import paths changes. Previously the generator would add the new correct import but leave the old stale import behind, forcing manual cleanup and leaving CI in a bad state.

This re-introduces StaleImportRemover (reverted in #35) with a fix for the regression that caused the original rollback: it now only removes imports whose leaf class is the operation's own Query, Mutation, or matching FailedException. Sibling classes under the same operation namespace (Data\..., Error\...) are left untouched because the remover has no way to tell whether they are still in use.

PlanExecutor also now collects the full set of valid operation FQCNs across the entire plan — not just the ones injected into the current file — so an @throws SomeQueryFailedException in a file that does not itself use the query is preserved as long as the hash still points to a planned operation.

Show diff on --ensure-sync mismatch

When --ensure-sync detected drift between generated and on-disk files, it only printed <path> content does not match expectations. In practice you still had to run the generator locally to understand what actually changed — CI logs were useless for diagnosing why a file was out of sync.

Render a colorized unified diff (red/green, @@ hunks) for every mismatched file so the CI log alone makes the cause obvious. Uses sebastian/diff, which is already available transitively via PHPUnit; promoted to a direct runtime dependency.

ruudk added 2 commits April 18, 2026 08:30
When a file is moved or refactored, the hash in generated import paths
changes. Previously the generator would add the new correct import but
leave the old stale import behind, forcing manual cleanup and leaving
CI in a bad state.

This re-introduces `StaleImportRemover` (reverted in #35) with a fix
for the regression that caused the original rollback: it now only
removes imports whose leaf class is the operation's own `Query`,
`Mutation`, or matching `FailedException`. Sibling classes under the
same operation namespace (`Data\...`, `Error\...`) are left untouched
because the remover has no way to tell whether they are still in use.

`PlanExecutor` also now collects the full set of valid operation
FQCNs across the entire plan — not just the ones injected into the
current file — so an `@throws SomeQueryFailedException` in a file
that does not itself use the query is preserved as long as the hash
still points to a planned operation.
When `--ensure-sync` detected drift between generated and on-disk
files, it only printed `<path> content does not match expectations`.
In practice you still had to run the generator locally to understand
what actually changed — CI logs were useless for diagnosing why a
file was out of sync.

Render a colorized unified diff (red/green, `@@` hunks) for every
mismatched file so the CI log alone makes the cause obvious. Uses
`sebastian/diff`, which is already available transitively via
PHPUnit; promoted to a direct runtime dependency.
@ruudk ruudk merged commit fe78cc0 into main Apr 18, 2026
5 checks passed
@ruudk ruudk deleted the stale branch April 18, 2026 06:42
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.

1 participant