Skip to content

chore: add track-and-prune for generated files to avoid unnecessary rewrites#4150

Open
framitdavid wants to merge 2 commits intomainfrom
chore/codegen-prune-orphans
Open

chore: add track-and-prune for generated files to avoid unnecessary rewrites#4150
framitdavid wants to merge 2 commits intomainfrom
chore/codegen-prune-orphans

Conversation

@framitdavid
Copy link
Copy Markdown
Contributor

@framitdavid framitdavid commented Apr 29, 2026

Description

A simpler "delete all *.generated.* before gen runs" would also work, but:

  • Defeats the hash-based skip in saveTsFile, every file gets re-linted and re-written every run.
  • find -delete isn't cross-platform (no PowerShell).

Track-and-prune only touches files that are actually orphaned, so the happy path stays free.

Related Issue(s)

  • PR iteslf.

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Summary by CodeRabbit

  • Chores
    • Enhanced code generation cleanup by removing orphaned generated files from the layout directory, ensuring the generated artifact set remains accurate and consistent after each build.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

The codegen script now includes post-generation cleanup logic that scans src/layout for stale .generated.ts and .generated.tsx files, compares them against the expected set computed from sortedKeys, and removes any orphaned generated files not in the expected set.

Changes

Cohort / File(s) Summary
Codegen Cleanup Logic
src/codegen/run.ts
Added post-generation maintenance that scans src/layout directory for orphaned .generated.ts/.generated.tsx files, computes the expected set of generated artifacts, and removes files not matching the expected output set to prevent stale generated files from persisting on disk.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: implementing a track-and-prune mechanism for generated files to prevent unnecessary rewrites and cleanup orphaned outputs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed PR description covers the motivation, implementation approach, and all required verification/QA items with appropriate selections.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/codegen-prune-orphans

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@framitdavid framitdavid added the taskforce/next Issues that belongs to the named task-force label Apr 29, 2026
@framitdavid framitdavid moved this to 🔎 In review in Team Altinn Studio Apr 29, 2026
Copy link
Copy Markdown
Contributor

@olemartinorg olemartinorg left a comment

Choose a reason for hiding this comment

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

Nifty! 🥳 This hopefully solves all the remaining issues we've had with sporadic code generation problems. 🤞

@framitdavid framitdavid added backport-ignore This PR is a new feature and should not be cherry-picked onto release branches ignore-for-release Pull requests to be ignored in release notes labels Apr 29, 2026
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 45%)
0.0% Condition Coverage on New Code (required ≥ 45%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-ignore This PR is a new feature and should not be cherry-picked onto release branches ignore-for-release Pull requests to be ignored in release notes taskforce/next Issues that belongs to the named task-force

Projects

Status: 🔎 In review

Development

Successfully merging this pull request may close these issues.

2 participants