Skip to content

[dev] [Marfuen] mariano/fix-formtype-sync-hyphen-underscore#2658

Merged
Marfuen merged 2 commits into
mainfrom
mariano/fix-formtype-sync-hyphen-underscore
Apr 24, 2026
Merged

[dev] [Marfuen] mariano/fix-formtype-sync-hyphen-underscore#2658
Marfuen merged 2 commits into
mainfrom
mariano/fix-formtype-sync-hyphen-underscore

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Apr 24, 2026

This is an automated pull request to merge mariano/fix-formtype-sync-hyphen-underscore into dev.
It was created by the [Auto Pull Request] action.


Summary by cubic

Normalize EvidenceFormType from hyphenated DB labels to underscored Prisma enum names to fix sync 500s and avoid false diffs between backfilled v1.0.0 and newer manifests. Keeps diffs accurate and syncs stable without a data migration.

  • Bug Fixes
    • Added form-type-normalize.ts to map hyphen → underscore for all @Map’d enum values.
    • Applied in framework-diff sanitize so identical types don’t show as add/remove.
    • Applied in framework-sync-apply before find/create/delete and stored normalized value in undo payloads.
    • Defensive normalization in framework-rollback for older undo payloads.

Written for commit adcf60b. Summary will update on new commits.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Apr 24, 2026 1:36pm
comp-framework-editor Ready Ready Preview, Comment Apr 24, 2026 1:36pm
portal Ready Ready Preview, Comment Apr 24, 2026 1:36pm

Request Review

Sync to a newly-published framework version was 500ing on prod for any
customer whose instance was pinned to a backfilled v1.0.0. Root cause:

- EvidenceFormType has `@map` directives, so underscored Prisma enum
  names (`infrastructure_inventory`) have hyphenated DB labels
  (`infrastructure-inventory`).
- The one-shot backfill data migration serialized doc types via
  `to_jsonb(ct."documentTypes"::text[])`, which renders the DB @Map'd
  hyphen form. So every backfilled v1.0.0 manifest stored hyphens.
- The TS manifest builder reads `ct.documentTypes` from Prisma client,
  which returns the underscored Prisma enum name. So CX-published
  v2+ manifests store underscores.
- When a customer synced v1.0.0 -> v2, the diff treated every doc type
  on every control as an add-underscore + remove-hyphen pair. The
  remove path called `controlDocumentType.findUnique({ formType:
  "infrastructure-inventory" })`; Prisma 7's strict enum validator
  rejected the hyphen form and 500'd the whole sync transaction.

Fix normalizes to the Prisma-client (underscored) form:
- new form-type-normalize.ts maps hyphens -> underscores for every
  @Map'd EvidenceFormType value
- framework-diff.sanitizeManifestEdges applies it before diffing, so
  the diff doesn't spuriously report identical types as add+remove
- framework-sync-apply normalizes edge.formType before every Prisma
  call (belt-and-suspenders)
- framework-rollback defensively normalizes stored undo payloads in
  case an older sync persisted the raw hyphen value

Existing backfilled manifests don't need to be rewritten - they're
normalized at read time.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Marfuen Marfuen force-pushed the mariano/fix-formtype-sync-hyphen-underscore branch from 1b522e8 to 91f4e08 Compare April 24, 2026 13:21
@vercel vercel Bot temporarily deployed to Preview – app April 24, 2026 13:21 Inactive
@vercel vercel Bot temporarily deployed to Preview – portal April 24, 2026 13:21 Inactive
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/api/src/frameworks/framework-versioning/form-type-normalize.ts">

<violation number="1" location="apps/api/src/frameworks/framework-versioning/form-type-normalize.ts:18">
P2: This introduces substantial duplicate mapping logic; reuse the shared `EXTERNAL_TO_DB_EVIDENCE_FORM_TYPE` source to avoid drift and future form-type mismatches.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread apps/api/src/frameworks/framework-versioning/form-type-normalize.ts Outdated
@Marfuen Marfuen merged commit 05f44eb into main Apr 24, 2026
11 of 14 checks passed
@Marfuen Marfuen deleted the mariano/fix-formtype-sync-hyphen-underscore branch April 24, 2026 13:30
@claudfuen
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.32.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants