Skip to content

fix(api): preserve orderForm sales channel in validateCart - #3435

Merged
eduardoformiga merged 11 commits into
devfrom
fix/validate-cart-stale-sales-channel
Aug 12, 2026
Merged

fix(api): preserve orderForm sales channel in validateCart#3435
eduardoformiga merged 11 commits into
devfrom
fix/validate-cart-stale-sales-channel

Conversation

@eduardoformiga

@eduardoformiga eduardoformiga commented Aug 6, 2026

Copy link
Copy Markdown
Member

What's the purpose of this pull request?

After returning from Quick Order (or similar external checkout flows), validateCart was sending a stale session sc on the orderForm GET. Checkout recalculated the cart under the wrong trade policy and dropped items only available in the orderForm's sales channel (e.g. SC 4). Tracked in SO-641 / #team-faststore.

How it works?

API (validateCart)

  • For existing carts, the first orderForm GET uses preserveSalesChannel (omits ?sc=) so Checkout keeps the cart's current sales channel.
  • When the cart etag is stale (external change), adopt orderForm.salesChannel into the GraphQL channel context.
  • When the cart is not stale and session SC diverges (e.g. locale/binding switch), re-fetch with the session SC so intentional channel changes still work.

Core

  • Defer client validateCart until the first validateSession completes (3s timeout), reducing the race where cart validates with a stale session.channel.

Before / After

Antes Depois
Screenshot 2026-08-06 at 18 18 47 Screenshot 2026-08-06 at 18 18 27

Cole os prints na tabela acima (Arrastar e soltar no editor do GitHub).
Antes: homebrewqa.fast.storeValidateCartMutation / ValidateSession.
Depois: sandbox preview — ValidateSession e ValidateCartMutation.

How to test it?

Preview URL (sandbox): https://sfj-119ced8--storeframework.preview.vtex.app

QA store PR: https://github.com/vtex-sites/faststoreqa.store/pull/907

  • Unit: cd packages/api && pnpm vitest run test/unit/platforms/vtex/utils/cartSalesChannel.test.ts test/unit/platforms/vtex/clients/commerce/index.test.ts
  • Core: cd packages/core && pnpm vitest run test/sdk/cart/waitForSessionValidated.test.ts
  • Integration: cd packages/api && pnpm vitest run test/integration/mutations.test.ts
  • Manual (thread repro / Quick Order):
    1. Force session SC ≠ default, add an SC-only SKU via Checkout API (or use Quick Order with SC 4).
    2. Reload / return to FastStore.
    3. Cart items should remain; validateCart must not wipe them.
    4. Locale/binding SC switch should still recalculate the cart under the new session SC.

Starters Deploy Preview

References

Checklist

  • PR title and commit messages follow Conventional Commits
  • Added a label according to the PR goal (bug)
  • No pnpm-lock.yaml changes
  • PR description

Made with Cursor

Summary by CodeRabbit

Bug Fixes

  • Improved cart validation when sales channels change, including locale switches and external cart updates.
  • Preserved existing cart sales channels while ensuring new carts use the current channel.
  • Prevented checkout recalculation issues caused by mismatched session and cart settings.
  • Cart validation now waits for session validation to complete, reducing race conditions.
  • Preserved adopted sales-channel information in returned order details.

Tests

  • Added coverage for sales-channel synchronization, cart refresh behavior, stale carts, and session-validation timing.

Avoid wiping cart items after Quick Order by omitting stale session `sc`
on the initial orderForm GET and adopting the orderForm SC when the cart
etag is stale. Also defer client validateCart until the first
validateSession completes.
@eduardoformiga
eduardoformiga requested a review from a team as a code owner August 6, 2026 20:49
@eduardoformiga
eduardoformiga requested review from lucasfp13 and ommeirelles and removed request for a team August 6, 2026 20:49
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 31ad018c-4530-4d17-b220-41aabbe94558

📥 Commits

Reviewing files that changed from the base of the PR and between 8943da7 and c825e8c.

📒 Files selected for processing (1)
  • packages/api/test/integration/mutations.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/api/test/integration/mutations.test.ts

Walkthrough

The PR coordinates session validation with cart validation and adds VTEX sales-channel synchronization. Existing carts can preserve their sales channel, stale carts can adopt order-form channels, and returned carts can include the adopted channel.

Changes

VTEX cart validation

Layer / File(s) Summary
Session validation coordination
packages/core/src/sdk/session/index.ts, packages/core/src/sdk/cart/waitForSessionValidated.ts, packages/core/src/sdk/cart/index.ts, packages/core/src/sdk/session/syncSalesChannelFromOrderForm.ts, packages/core/test/sdk/cart/waitForSessionValidated.test.ts, packages/core/test/sdk/session/syncSalesChannelFromOrderForm.test.ts
Exports session validation state. Cart validation waits for validation before reading session state. Silent updates synchronize adopted sales channels without triggering cart revalidation.
Sales-channel order-form behavior
packages/api/src/platforms/vtex/clients/commerce/index.ts, packages/api/src/platforms/vtex/utils/cartSalesChannel.ts, packages/api/src/platforms/vtex/resolvers/validateSession.ts, packages/api/src/platforms/vtex/typeDefs/order.graphql, packages/api/test/unit/platforms/vtex/clients/commerce/index.test.ts, packages/api/test/unit/platforms/vtex/utils/cartSalesChannel.test.ts
Adds conditional sc query construction, channel divergence detection, explicit-channel preservation, and StoreOrder.salesChannel.
Cart validation integration
packages/api/src/platforms/vtex/resolvers/validateCart.ts, packages/api/test/mocks/ValidateCartMutation.ts, packages/api/test/integration/mutations.test.ts
Preserves existing order-form channels during initial fetches, adopts divergent channels before cart operations, and propagates adopted channel data in returned orders.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SessionValidation
  participant CartValidation
  participant VTEXOrderForm
  participant SalesChannelState
  SessionValidation->>CartValidation: complete session validation
  CartValidation->>VTEXOrderForm: fetch order form with channel preservation
  VTEXOrderForm-->>CartValidation: return order form and sales channel
  CartValidation->>SalesChannelState: evaluate channel divergence
  SalesChannelState-->>CartValidation: return adopted channel
  CartValidation->>VTEXOrderForm: update cart using adopted channel
  CartValidation-->>SessionValidation: silently synchronize session channel
Loading

Possibly related PRs

  • vtex/faststore#3178: Both PRs modify VTEX checkout.orderForm request construction and validateCart retrieval.
  • vtex/faststore#3441: Both PRs modify validateCart, orderFormToCart, and returned order data.

Suggested labels: bug

Suggested reviewers: lucasfp13, ommeirelles, hellofanny

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary change: preserving the orderForm sales channel during validateCart.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/validate-cart-stale-sales-channel

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

@codesandbox-ci

codesandbox-ci Bot commented Aug 6, 2026

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/api/src/platforms/vtex/resolvers/validateCart.ts (1)

381-448: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add resolver-level integration coverage for both sales-channel branches.

Add *.int.test.ts cases that invoke validateCart and assert the initial Checkout URL, conditional refetch URL, and returned cart state for stale external carts and non-stale session-channel changes. The existing salesChannelStaleFetch fixture only covers the catalog lookup.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/api/src/platforms/vtex/resolvers/validateCart.ts` around lines 381 -
448, Add resolver-level integration tests invoking validateCart for both stale
external carts and non-stale session-channel changes. Assert the initial
Checkout request URL, whether the conditional refetch occurs with the expected
sales channel, and the returned cart state; do not rely solely on the
salesChannelStaleFetch catalog fixture.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/api/test/unit/platforms/vtex/clients/commerce.test.ts`:
- Around line 75-128: Rename the unit test file from commerce.test.ts to
index.test.ts and place it under the commerce directory so it matches the tested
source module commerce/index.ts and the required test-file naming convention.
Preserve the existing orderForm test contents unchanged.

In `@packages/api/test/unit/platforms/vtex/utils/cartSalesChannel.test.ts`:
- Line 45: Update the test around the JSON.parse call to explicitly throw when
result is null, allowing TypeScript to narrow it to a string before parsing;
remove the result as string assertion while preserving the existing object
match.

---

Nitpick comments:
In `@packages/api/src/platforms/vtex/resolvers/validateCart.ts`:
- Around line 381-448: Add resolver-level integration tests invoking
validateCart for both stale external carts and non-stale session-channel
changes. Assert the initial Checkout request URL, whether the conditional
refetch occurs with the expected sales channel, and the returned cart state; do
not rely solely on the salesChannelStaleFetch catalog fixture.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 61dd66c4-c837-4178-b095-8bdcf9e8fbb5

📥 Commits

Reviewing files that changed from the base of the PR and between 975dc71 and 2336cda.

📒 Files selected for processing (8)
  • packages/api/src/platforms/vtex/clients/commerce/index.ts
  • packages/api/src/platforms/vtex/resolvers/validateCart.ts
  • packages/api/src/platforms/vtex/utils/cartSalesChannel.ts
  • packages/api/test/mocks/ValidateCartMutation.ts
  • packages/api/test/unit/platforms/vtex/clients/commerce.test.ts
  • packages/api/test/unit/platforms/vtex/utils/cartSalesChannel.test.ts
  • packages/core/src/sdk/cart/index.ts
  • packages/core/src/sdk/session/index.ts

Comment thread packages/api/test/unit/platforms/vtex/utils/cartSalesChannel.test.ts Outdated
Align the unit test path with the commerce/index.ts source module.
Extract SC adoption glue to reduce cognitive complexity, flatten nested
template literals in checkout.orderForm, and narrow the cartSalesChannel
test without a type assertion.
Extract the session-wait helper so unit tests can exercise immediate,
subscribe, race, and timeout paths under the Quality Gate threshold.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/test/sdk/cart/waitForSessionValidated.test.ts`:
- Around line 31-43: Update both Store<boolean> mocks used by
waitForSessionValidated to include the required readInitial method, returning
the mock store’s initial boolean value consistently with read. Keep the existing
subscribe, unsubscribe, and set behavior unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d1bd220b-92d0-4189-84b6-dcda5026716f

📥 Commits

Reviewing files that changed from the base of the PR and between 3211231 and 2dbe295.

📒 Files selected for processing (3)
  • packages/core/src/sdk/cart/index.ts
  • packages/core/src/sdk/cart/waitForSessionValidated.ts
  • packages/core/test/sdk/cart/waitForSessionValidated.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/sdk/cart/index.ts

Comment thread packages/core/test/sdk/cart/waitForSessionValidated.test.ts
@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

npm i https://pkg.pr.new/vtex/faststore/@faststore/api@5726ef5

@faststore/cli

npm i https://pkg.pr.new/vtex/faststore/@faststore/cli@5726ef5

@faststore/components

npm i https://pkg.pr.new/vtex/faststore/@faststore/components@5726ef5

@faststore/core

npm i https://pkg.pr.new/vtex/faststore/@faststore/core@5726ef5

@faststore/diagnostics

npm i https://pkg.pr.new/vtex/faststore/@faststore/diagnostics@5726ef5

@faststore/lighthouse

npm i https://pkg.pr.new/vtex/faststore/@faststore/lighthouse@5726ef5

@faststore/sdk

npm i https://pkg.pr.new/vtex/faststore/@faststore/sdk@5726ef5

@faststore/ui

npm i https://pkg.pr.new/vtex/faststore/@faststore/ui@5726ef5

commit: 5726ef5

@renatomaurovtex renatomaurovtex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the full resolver flow on the head commit, plus the SDK store internals that the new client-side wait relies on. The design is sound: preserve the orderForm's SC on the first GET, let the orderForm win when the cart is externally stale, let the session win otherwise. Verified that the session↔cart import cycle is pre-existing (session/index.ts already imported cartStore) and the new hasValidatedSessionStore import is only dereferenced at call time, so module init order is safe. Also verified the 3s wait is effectively a safety net only: persisted always calls store.set() on IDB hydration and optimistic validates on every set, so validateSession fires on every page load and hasValidatedSessionStore flips quickly.

One scenario I couldn't convince myself is covered:

packages/api/src/platforms/vtex/resolvers/validateCart.ts

🟠 Persistent session↔orderForm SC divergence re-drops the items one request later. The stale-etag pass adopts the orderForm SC only into the request-scoped context (mutateChannelContext), then setOrderFormEtag makes the cart non-stale. If the client session never converges to the orderForm SC — validateSession derives it from Session Manager (store?.channel?.value ?? channel.salesChannel), so this happens whenever the external flow advanced the orderForm but not vtex_session — the next validateCart takes the non-stale path, shouldRefetchOrderFormWithSessionSalesChannel sees session 1 ≠ orderForm 4, and re-fetches with sc=1: Checkout recalculates under the stale session SC and drops the SC-4-only items. That's the original bug, deferred by one request.

Two asks:

  1. Confirm the Quick Order flow propagates its SC into Session Manager (store.channel) — if yes, this is a non-issue for SO-641 and the divergence refetch only fires for genuine in-session switches.
  2. Either way, add a repro step to "How to test it": reload twice after returning from Quick Order. The current steps only prove the first validation.

If Session Manager does not converge, consider gating the refetch on an SC change observed in-session (e.g. channel actually mutated since the last validation) instead of any divergence.

🟡 No resolver-level test for the new branches. The pure helpers are well covered, but nothing asserts that validateCart actually issues the second GET with sc on divergence, or that the adopted channel reaches mutateChannelContext on the stale path. A mutations.test.ts case with session SC ≠ orderForm SC (non-stale) asserting the second fetch URL would lock the behavior against refactors.

💬 adoptOrderFormSalesChannelIfNeeded(ctx, orderForm, isStale) is only called inside if (isStale), so the third parameter is always true — the helper's re-check is dead in practice. Fine to keep for the pure-function test surface, but the call site could drop the flag.

packages/core/src/sdk/cart/waitForSessionValidated.ts

The read → subscribe → re-read race handling is correct, and resolving on timeout (rather than rejecting) is the right degradation. Nice test coverage, including the between-read-and-subscribe race.

Verdict: Approved with comments

Blocking (🔴/🟠):

  • 🟠 Answer the two-request divergence question above (and add the double-reload repro step) before merge — if Session Manager doesn't carry the external SC, this reintroduces SO-641 one request later.

Non-blocking (🟡/💬):

  • 🟡 Resolver-level integration test for the divergence refetch / SC adoption.
  • 💬 Redundant isStale param at the adoption call site.

Checks to confirm before merge: pnpm turbo run test --filter=@faststore/api --filter=@faststore/core · build · pnpm size (core/sdk touched)

@hellofanny

Copy link
Copy Markdown
Contributor

Reviewed the full validateCart flow on the head commit, plus the session/cart store internals the client-side wait depends on. Ran the suites locally — cartSalesChannel, commerce/index, mutations.test.ts and the new core test all pass, and CI is green. The three-way split (preserve the orderForm SC on the first GET, orderForm wins when externally stale, session wins otherwise) reads well. Four things below, one of which I think is worth resolving before merge.

1. The new core test file doesn't type-check

Both hand-rolled Store<boolean> mocks in packages/core/test/sdk/cart/waitForSessionValidated.test.ts (lines 31–43 and 71–88) omit readInitial, which the Store<T> contract requires:

test/sdk/cart/waitForSessionValidated.test.ts(45,45): error TS2345
test/sdk/cart/waitForSessionValidated.test.ts(90,42): error TS2345

Vitest passes because it strips types instead of checking them, and CI stays green because no workflow runs tsc — but test/**/*.ts is inside packages/core/tsconfig.json's include, so this is a red squiggle for anyone who opens the file. Adding readInitial: vi.fn(() => false) to both mocks clears it.

2. The session likely won't converge to the orderForm SC, so a second validateCart can undo the fix

The stale branch adopts SC 4 into the request-scoped ctx.storage.channel, but validateCart returns only the cart — the adopted channel never reaches the browser, so the client keeps sending its old session.channel.

The PR is betting on validateSession correcting that. Tracing it, I don't think it can: validateSession builds its Session Manager params from the browser's session (const salesChannel = params.get('sc') ?? channel.salesChannel; params.set('sc', salesChannel)), PATCHes /api/sessions with that value, and then derives the new channel from store?.channel?.value — i.e. the value it just wrote. Unless the return URL carries an explicit ?sc=4, the stale SC is self-reinforcing.

If that holds, the sequence after Quick Order is:

  • Call 1 — etag stale → orderForm SC 4 adopted → correct cart returned, new etag written.
  • Call 2 (any navigation or add-to-cart) — etag now fresh, so isStale is falseshouldRefetchOrderFormWithSessionSalesChannel('1', '4', false) returns true → re-fetch with sc=1 → Checkout recalculates under the old trade policy and the SC-4 items drop again.

The QA repro in the description only covers the first reload, so this wouldn't have shown up. Could you re-run it with a second validateCart (client-side navigation, or add an item after returning) and confirm the cart survives? If it doesn't, the fix probably needs the adopted channel to reach the client — returning it on the mutation, or having the stale branch write the SC through to Session Manager — rather than relying on the session to self-correct.

3. Same branch adds a Checkout round trip on the cart critical path

While session SC and orderForm SC diverge, every validateCart now makes two sequential Checkout GETs. There's no guard against a persistent mismatch — if Checkout declines to move the orderForm (e.g. the SKU isn't in the target trade policy, so it keeps its own SC), the condition never stops being true and the extra request is permanent, not one-off. Worth a bound or a log line, since it's invisible in testing but sits on add-to-cart.

4. Neither new resolver branch is covered above the helper level

cartSalesChannel.test.ts covers the pure predicates and commerce/index.test.ts covers URL construction, but nothing exercises validateCart itself with divergent channels — the integration mocks pass precisely because mock orderForm SC and session SC are both '1', so the re-fetch branch never runs. Given #2, a resolver-level test for both branches (stale + adopt, non-stale + refetch) is the coverage I'd most want here.

Also worth knowing (non-blocking)

optimistic in packages/sdk/src/store/optimistic.ts serializes validations through a promise queue, so the up-to-3s wait delays not just the first cart validation but anything queued behind it. The failure mode is safe (hasValidatedStore is set in a finally, so session errors still release the wait) and it's a one-time cost per page, but in the normal path every first cart validation now waits a full session round trip before it starts — worth a quick measurement given #2 may mean it isn't buying the convergence it was added for.

Two cosmetic leftovers: adoptOrderFormSalesChannelIfNeeded re-checks isOrderFormStaleFlag internally although it's only called inside if (isStale), and the qs ? '?' + qs : '' guard in the commerce client is unreachable since preserveSalesChannel && id always adds refreshOutdatedData.

Stop refetching Checkout with a lagging session SC on later validations,
which wiped Quick Order items one request after the first preserve/adopt.
Expose optional StoreOrder.salesChannel when SC was adopted from a stale cart.
Keep Checkout on the orderForm trade policy when session SC lags, return
the adopted SC from validateCart, and silently align fs::session so later
requests use the correct channel without revalidating the cart mid-flight.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/api/test/integration/mutations.test.ts`:
- Around line 194-298: Move the two validateCart integration tests around the
divergent and stale sales-channel scenarios from mutations.test.ts into a new
validateCart.int.test.ts file. Preserve their setup, mocks, assertions, and
required imports so pnpm test:int discovers them, while keeping
mutations.test.ts for unit tests only.
- Around line 169-180: Update withOrderFormSalesChannel to return the widened
object shape produced after replacing result, rather than claiming the original
generic subtype T; preserve the generic input constraint and merged fields.
Rename the test file from mutations.test.ts to mutations.int.test.ts to match
the integration-test naming convention.

In `@packages/core/src/sdk/session/syncSalesChannelFromOrderForm.ts`:
- Around line 23-29: Update the channel parsing in syncSalesChannelFromOrderForm
so parsed values are accepted only when they are non-null objects; otherwise
reset channel to an empty record before the salesChannel comparison. Add
coverage for valid non-object JSON, including null, and preserve the existing
comparison behavior for valid channel objects.

In `@packages/core/test/sdk/session/syncSalesChannelFromOrderForm.test.ts`:
- Around line 5-16: Update the baseSession fixture to return a complete Session
object by supplying every required Session field, then remove the `as Session`
type assertion. Keep the existing salesChannel, currency, locale, country,
channel, and person values unchanged while relying on TypeScript to validate the
fixture and expose future Session contract changes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 478e3803-6bde-4b4f-90cf-6afacb846511

📥 Commits

Reviewing files that changed from the base of the PR and between 2dbe295 and 8943da7.

⛔ Files ignored due to path filters (4)
  • packages/api/src/__generated__/schema.ts is excluded by !**/__generated__/** and included by packages/**
  • packages/api/test/integration/__snapshots__/mutations.test.ts.snap is excluded by !**/*.snap and included by packages/**
  • packages/core/@generated/gql.ts is excluded by !**/@generated/**, !**/@generated/** and included by packages/**
  • packages/core/@generated/graphql.ts is excluded by !**/@generated/**, !**/@generated/** and included by packages/**
📒 Files selected for processing (14)
  • packages/api/src/platforms/vtex/clients/commerce/index.ts
  • packages/api/src/platforms/vtex/resolvers/validateCart.ts
  • packages/api/src/platforms/vtex/resolvers/validateSession.ts
  • packages/api/src/platforms/vtex/typeDefs/order.graphql
  • packages/api/src/platforms/vtex/utils/cartSalesChannel.ts
  • packages/api/test/integration/mutations.test.ts
  • packages/api/test/mocks/ValidateCartMutation.ts
  • packages/api/test/unit/platforms/vtex/utils/cartSalesChannel.test.ts
  • packages/core/src/sdk/cart/index.ts
  • packages/core/src/sdk/cart/waitForSessionValidated.ts
  • packages/core/src/sdk/session/index.ts
  • packages/core/src/sdk/session/syncSalesChannelFromOrderForm.ts
  • packages/core/test/sdk/cart/waitForSessionValidated.test.ts
  • packages/core/test/sdk/session/syncSalesChannelFromOrderForm.test.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/api/test/mocks/ValidateCartMutation.ts
  • packages/api/src/platforms/vtex/clients/commerce/index.ts
  • packages/core/test/sdk/cart/waitForSessionValidated.test.ts
  • packages/core/src/sdk/cart/waitForSessionValidated.ts
  • packages/core/src/sdk/session/index.ts

Comment thread packages/api/test/integration/mutations.test.ts
Comment thread packages/api/test/integration/mutations.test.ts
Comment thread packages/core/src/sdk/session/syncSalesChannelFromOrderForm.ts Outdated
Comment thread packages/core/test/sdk/session/syncSalesChannelFromOrderForm.test.ts Outdated
Lower validateCart/validateSession cognitive complexity, guard non-object
channel JSON before syncing adopted SC, and add coverage for the new paths.
Extract session helpers into a dedicated util and add unit tests so the
validateSession refactor no longer tanks Coverage on New Code.
@sonar-workflows

Copy link
Copy Markdown

@eduardoformiga
eduardoformiga merged commit 4a1290d into dev Aug 12, 2026
12 of 13 checks passed
@eduardoformiga
eduardoformiga deleted the fix/validate-cart-stale-sales-channel branch August 12, 2026 02:47
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.

3 participants