Preview all configuration drafts safely

This Dealops 2 / Dealops 3 PR makes synthetic configuration previews generate order forms from unpublished formula, binding, flow, catalog, and approval drafts without letting real quotes opt into draft behavior.

Author: @mehulshinde PR: #7570 Linear: DEA-8091 State: open Base: main Head: codex/dea-8091-preview-all-drafts Files: 68 Diff: +2801 / -423 Note: diff shown here is truncated

What it adds

Configuration preview now stays valid for order-form formula drafts and order-form spec/template-binding drafts, not just pricing/catalog/flow drafts.

Admins can generate a recorded order form from a verified synthetic preview.

What it hardens

The stored synthetic opportunity becomes the preview authority. URL flags, quote names, and mutable input.isPreview stamps no longer activate drafts for real quotes.

What it coordinates

Draft approval rules and draft formulas are evaluated together for previews, while published approval evidence continues to require immutable published formula revisions.

What it protects

Synthetic previews can generate test order forms, but CRM writeback, automatic writeback, approval submission, and signature sends remain blocked for preview quotes.

Preview identity
Draft formulas
Approval gate
Export spec context
Client policy
Test coverage

1. Why this exists

Before
  • Preview eligibility could expire when the only remaining drafts were order-form formulas or template bindings.
  • Preview links disabled order-form generation even when the admin wanted a test document.
  • Draft approval rules could be evaluated against published formula versions.
  • A copied/renamed preview option could lose its input preview stamp.
After
  • Any draft reported by v3Admin.getDraftStatus keeps preview mode alive.
  • Verified synthetic previews can run GenerateOrderForm and SaveAndQuit.
  • Approval previews resolve draft workflow rules and draft formula versions from one source.
  • Stored quote/opportunity identity, not mutable URL/input markers, decides preview status.
Scope note: the supplied diff is truncated, so this explainer is based on the PR description, file list, and visible diff. The visible changes cover the main client gates, server approval/export paths, preview identity, formula versioning, and E2E tests.

2. What changes

Preview eligibility

The client stops enumerating a fixed draft list and treats any truthy draft flag as active:

Object.values(draftData?.drafts ?? {}).some(Boolean)

This picks up new keys like orderFormFormulas and orderFormSpec.

Preview identity

Preview checks move to shared identity helpers such as resolveQuotePreview, resolveQuotePreviews, and isPreviewOpportunity.

The server verifies organization ownership and the quote/opportunity link before enabling draft behavior.

Generate policy

Client and server share decideOrderFormGeneration from packages/types/v2/flows/FinishSpec.

The server re-runs the gate at export dispatch and worker execution.

Area Representative files Reviewer signal
Client PricingFlowPage.tsx, CreateSubmitQuoteModal.tsx, OrderFormVersionsDrawer.tsx, useGenerateOrderForm.tsx Preview behavior comes from the loaded opportunity, not from ?preview=true. Generate is enabled only through the shared policy.
Identity dealops3/preview/identity.ts, packages/types/v2/crmOpportunity.ts The stored synthetic opportunity is the single authority. Real quotes cannot spoof preview behavior with a quote input flag.
Approvals PricingQuoteApprovalController.ts, approvals/formulas.ts, approvals/v2Bridge.ts Approval bundles carry resolved isPreview. Draft predictions do not produce published formula evidence.
Formula versions formulas/persistence/resolveVersion.ts, formulaReleaseValidation.ts, approvalFormulaDrafts.ts Draft and published formula metadata share validation. Draft runtime formulas retain revision: null.
Export pricingQuoteExport/specContext.ts, pricingQuoteExport/exportPolicy.ts, orderFormFormula/persistence/source.ts, previewBinding.ts One export context supplies draft pricing/catalog/flow overrides and draft order-form bindings/formulas.
Tests + lint approvalDraftPreview.e2e.ts, configurationPreview.e2e.ts, eslint.config.js New E2E coverage exercises draft approvals, formula-only drafts, copied preview options, export regressions, and hard-coded preview-prefix prevention.

3. How it works

Preview authority flow

1. Stored quote
Server receives quote id and optional opportunity id.
2. Link check
Quote must belong to the organization and match the opportunity.
3. Synthetic opp
Opportunity identity uses the shared preview predicate/prefix.
4. Draft source
Only verified previews load draft specs/formulas.
5. Guard rails
Writeback, approval submission, and signature sends stay blocked.
Client gate

Components now pass the loaded opportunity into order-form generation:

const isPreview = isPreviewOpportunity(opportunity);

decideOrderFormGeneration({
  gateEnabled,
  approvalsEnabled,
  isPreview,
  activeStatus,
  predictedGroupCount,
});

A preview URL alone can still show the admin preview route, but it does not make a real quote draft-aware or generation-eligible.

Server gate

Recorded order-form generation goes through one export policy boundary:

if (!isRecordedOrderFormGeneration(args)) return;
await assertOrderFormGenerationAllowed(args);

The same check runs before queuing and again inside the export worker, so stale queued work cannot bypass approval requirements.

Approval formula resolution

Decision source
✓
Preview quote: load draft workflow spec and overlay draft approval formulas onto the active manifest.
✓
Live quote: load only the published release and require published formula revisions.
!
Draft formula metadata: validated through resolveFormulaVersion; drafts keep revision: null.
×
Published evidence: buildFormulaEvidence rejects draft decisions so draft predictions cannot become approval audit evidence.

Order-form export snapshot

Load quotes
Export receives the requested pricing quote ids.
Resolve previews
resolveQuotePreviews returns per-quote identity.
Build context
loadExportSpecContext chooses draft or published pricing, datasheet, and flow data.
Pick binding
Preview exports load selected template draft bindings and formula versions.
Render doc
Generated replacements use the same draft catalog names and formulas as preview pricing.
Copied preview options

A copied pricing option can lose the original input.isPreview stamp and still remain a preview if it is stored under the synthetic opportunity.

Real quote controls

A real quote with input.isPreview: true, a renamed option, or a preview URL continues to use published configuration and live approval requirements.

Prefix hygiene

Client and server lint now block new literal PREVIEW- usage outside tests and fixtures. Code should use the shared predicate or prefix constant.

4. Validation added

New E2E suites
1,065+

New visible lines across approvalDraftPreview.e2e.ts and configurationPreview.e2e.ts.

  • Formula-only drafts.
  • Draft rules + draft formulas.
  • New never-published formulas.
  • Rollback manifest behavior.
  • Copied preview option export regression.
Policy tests
shared

orderFormApprovalGate.test.ts verifies the same generation policy the client uses.

  • Preview generation allowed.
  • Approved live quote allowed.
  • Pending/rejected/unsubmitted live quote predicts and forbids when groups are required.
Reported local + CI results
pass
  • 14,236 Mocha server tests.
  • 3,557 Jest server tests.
  • 109 order-form E2E tests, including 13 draft approval scenarios.
  • 10 attribute-approval E2E tests.

5. What it doesn't change

Explicit non-goals

6. Risks / rollback / open questions

Risk: identity is now central. The preview decision depends on stored quote/opportunity relationships. Bugs in resolveQuotePreview would affect approvals, export context, and writeback blocking. The PR adds targeted identity tests and E2E coverage for copied options, wrong organizations, and mismatched opportunities.
Risk: draft formulas fail closed. Corrupt or incompatible draft formula metadata now fails preview evaluation instead of silently falling back to published behavior. That is safer for approvals, but admins may see preview failures until the draft is fixed.
Rollback shape: order-form formula runtime remains behind existing runtime flags for enabled orgs, but the preview identity and generation-policy changes are broad code changes. A full rollback would revert this PR; a narrow operational mitigation is to disable affected order-form formula runtime usage where possible.
Open validation gap from the PR description: browser E2E stubs Google/auth/queue I/O. Actual Google document creation was not exercised in the browser, though the export service path is covered with Google I/O replaced.