---
id: ATS-CRM-REG-012
scope: CAP-CRM-REG-012
product_area: crm
module: regions
revision: 3
status: proposed
approved_by: null
approved_at: null
source_sha:
  services-crm: a8d1364f1dd44b723bb5f9acba12f983e9ec8d69
  react-console: baf6dae382d6f41dce976c7f848667ccc37e076f
scenarios:
  - id: ATS-CRM-REG-012-01
    title: History and individual reads expose progress
    level: api
    proves:
      - BR-CAP-CRM-REG-012-01
    preconditions: 'The workspace has three runs, including equal start times.'
    steps: 'Read history using defaults and a smaller limit, then inspect a run.'
    expected: >-
      Ordering is newest first with identifier tie breaking, the limit bounds results and the record
      exposes progress.
    negative: false
    data_needs: Three recalculation history entries.
    bound_to:
      - TST-CRM-REG-053
      - TST-CRM-REG-047
    provenance: test
    source: >-
      services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.queries.integration.spec.js#listRegionRecalculations
      › answers the whole record of every run of the tenant, the newest first
    category: rule
    test_assertions:
      - >-
        services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.queries.integration.spec.js#listRegionRecalculations
        › answers the whole record of every run of the tenant, the newest first
      - >-
        services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.queries.integration.spec.js#listRegionRecalculations
        › answers at most the limit it was given, taking the newest runs
      - 'services-crm:modules/regions/tests/e2e/regions.e2e.spec.js#lists the recalculation'
      - 'services-crm:modules/regions/tests/e2e/regions.e2e.spec.js#reads the recalculation'
  - id: ATS-CRM-REG-012-02
    title: Status and counters cannot contradict completion
    level: api
    proves:
      - BR-CAP-CRM-REG-012-02
    preconditions: A run record exists.
    steps: >-
      Attempt completed status before the final phase, final phase without completion and more changed
      than examined.
    expected: Each inconsistent state is rejected.
    negative: true
    data_needs: A recalculation record.
    bound_to:
      - TST-CRM-REG-052
    provenance: test
    source: >-
      services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.integration.spec.js#refuses
      completed before the run is done
    category: invariant
    test_assertions:
      - >-
        services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.integration.spec.js#refuses
        completed before the run is done
      - >-
        services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.integration.spec.js#refuses
        done without completed
      - >-
        services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.integration.spec.js#refuses
        more records changed than examined
  - id: ATS-CRM-REG-012-03
    title: Ordinary failures retain redacted reasons
    level: api
    proves:
      - BR-CAP-CRM-REG-012-03
    preconditions: A database failure will interrupt the next batch.
    steps: Make two unsuccessful deliveries.
    expected: >-
      Both fail while the run stays running, and its reason excludes bound values, identifiers and SQL
      text.
    negative: false
    data_needs: A deliberately injected database error.
    bound_to:
      - TST-CRM-REG-059
    provenance: test
    source: >-
      services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js#the
      reason it records › answers the caller the error the batch failed with, so the queue delivers the
      event again
    category: failure
    test_assertions:
      - >-
        services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js#the
        reason it records › answers the caller the error the batch failed with, so the queue delivers the
        event again
      - >-
        services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js#the
        reason it records › records the redacted reason on a run it leaves running, so the next delivery
        can get past the cause
      - >-
        services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js#the
        reason it records › records no value of the batch that failed: not the contact, the tenant, the
        statement or its parameters
  - id: ATS-CRM-REG-012-04
    title: Only final failure terminates the run
    level: api
    proves:
      - BR-CAP-CRM-REG-012-04
    preconditions: The unfinished batch continues failing.
    steps: Fail a normal delivery and then the final delivery.
    expected: >-
      The earlier failure retains running status; the final failure marks the run failed when failure
      settlement succeeds.
    negative: false
    data_needs: An injected assignment failure.
    bound_to:
      - TST-CRM-REG-059
    provenance: test
    source: >-
      services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js#the
      reason it records › leaves that run running too: how many failures are enough is the queue’s
      decision, not the run’s
    category: transition
    test_assertions:
      - >-
        services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js#the
        reason it records › leaves that run running too: how many failures are enough is the queue’s
        decision, not the run’s
      - >-
        services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js#the
        last delivery of a run’s event › fails the run, because nothing will deliver its event again
  - id: ATS-CRM-REG-012-05
    title: Successful progress removes the failure reason
    level: api
    proves:
      - BR-CAP-CRM-REG-012-05
    preconditions: A run retains an earlier failure reason.
    steps: Process its remaining work successfully.
    expected: Completion retains no failure reason.
    negative: false
    data_needs: An unfinished run retaining a previous failure reason.
    bound_to:
      - TST-CRM-REG-059
    provenance: test
    source: >-
      services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js#a
      run that gets past what stopped it › answers the whole record of the completed run, with no reason
      left on it
    category: transition
    test_assertions:
      - >-
        services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js#a
        run that gets past what stopped it › answers the whole record of the completed run, with no
        reason left on it
      - >-
        services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js#a
        run that gets past what stopped it › clears the column itself, as the table holds it
  - id: ATS-CRM-REG-012-06
    title: Run reads cannot cross workspaces
    level: api
    proves:
      - BR-CAP-CRM-REG-012-06
    preconditions: A run belongs to another workspace.
    steps: Read it locally and request an unknown identifier.
    expected: Neither read finds a local run.
    negative: true
    data_needs: Two distinct customer workspaces.
    bound_to:
      - TST-CRM-REG-053
      - TST-CRM-REG-047
    provenance: test
    source: >-
      services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.queries.integration.spec.js#getRegionRecalculation
      › answers undefined in another tenant for the first tenant's run
    category: boundary
    test_assertions:
      - >-
        services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.queries.integration.spec.js#getRegionRecalculation
        › answers undefined in another tenant for the first tenant's run
      - >-
        services-crm:modules/regions/tests/e2e/regions.e2e.spec.js#answers 404 for a recalculation the
        tenant does not have
  - id: ATS-CRM-REG-012-07
    title: Retryable failure and recovery remain visible through run reads
    category: interaction
    level: api
    proves:
      - BR-CAP-CRM-REG-011-04
      - BR-CAP-CRM-REG-012-03
      - BR-CAP-CRM-REG-012-05
      - BR-CAP-CRM-REG-010-02
    preconditions: A run spans more than one batch and its next batch fails once.
    steps: >-
      Commit the first batch, fail the next delivery, read the run and policy currency, remove the fault
      and redeliver to completion.
    expected: >-
      Reads retain committed progress and a redacted running error before recovery; successful completion
      clears that error and covers only its recorded generation.
    negative: false
    data_needs: A run spans more than one batch and its next batch fails once.
    bound_to: []
    provenance: proposed
    source: WF-CRM-REG-003
    exercises:
      - CAP-CRM-REG-010
      - CAP-CRM-REG-011
      - CAP-CRM-REG-012
  - id: ATS-CRM-REG-012-08
    title: Failure-settlement failure preserves the original batch error
    category: failure
    level: api
    proves:
      - INV-DOM-CRM-REG-004-06
    preconditions: A run’s next batch fails and storing its failure reason also fails.
    steps: >-
      Deliver once with a recoverable fault and once as final receive while settlement remains
      unavailable.
    expected: >-
      The original batch error is rethrown and settlement failure is logged; final delivery can leave
      running status rather than guaranteeing failed settlement.
    negative: true
    data_needs: A run’s next batch fails and storing its failure reason also fails.
    bound_to: []
    provenance: proposed
    source: 'services-crm:modules/regions/services/region-assignment/region-recalculation.ts:recordFailure'
evidence:
  - >-
    services-crm: Examined the pinned regional implementation, its declared constraints and the
    supporting records.
  - 'react-console: Examined the pinned regional configuration surfaces and their available test evidence.'
  - >-
    services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.queries.integration.spec.js
  - 'services-crm:modules/regions/tests/e2e/regions.e2e.spec.js'
  - >-
    services-crm:modules/regions/tests/integration/services/persistence/region-recalculations.integration.spec.js
  - >-
    services-crm:modules/regions/tests/integration/services/region-assignment/region-recalculation-errors.integration.spec.js
coverage:
  rule: covered
  transition: covered
  validation: 'gap: FND-CRM-REG-057'
  permission: 'gap: FND-CRM-REG-057'
  edge: 'gap: FND-CRM-REG-057'
  failure: covered
  boundary: covered
  concurrency: 'gap: FND-CRM-REG-057'
  invariant: covered
  interaction: covered
---

# Monitor recalculation and recover from failure: Capability Test Specification

## Coverage

Each row links a required rule to its authored proof. A covered category records a specification; executable and remaining variant gaps stay in the finding register.

| Rule | Proved By |
|---|---|
| `BR-CAP-CRM-REG-012-01` | `ATS-CRM-REG-012-01` |
| `BR-CAP-CRM-REG-012-02` | `ATS-CRM-REG-012-02` |
| `BR-CAP-CRM-REG-012-03` | `ATS-CRM-REG-012-03`, `ATS-CRM-REG-012-07` |
| `BR-CAP-CRM-REG-012-04` | `ATS-CRM-REG-012-04` |
| `BR-CAP-CRM-REG-012-05` | `ATS-CRM-REG-012-05`, `ATS-CRM-REG-012-07` |
| `BR-CAP-CRM-REG-012-06` | `ATS-CRM-REG-012-06` |

## Interactions With Related Capabilities

Retryable failure and recovery remain visible through run reads. The interaction scenario connects apply the current policy across existing records with this capability. Cross-workflow expectations are proposed where no executable binding is present.
