---
id: TST-ACC-CLS-029
title: 'Command identity, competing requests and run changes'
kind: integration
product_area: accounting
module: close
revision: 1
status: draft
source_sha:
  services-accounting: f47cb263875bbc0c5640fba7dae6785ec32695f8
repository: services-accounting
files:
  - >-
    modules/fiscal-close/tests/integration/services/persistence/period-close-runs.integration.spec.js
implements:
  - ATS-ACC-CLS-008-02
environment: local
implementation_state: implemented
latest_result: not-run
latest_run_at: null
latest_run_ref: null
conformance: not-verified
estimated_minutes: 3
isolation: >-
  The suite owns test-identifier workspaces and fixture records, removed by its
  teardown.
binding_policy: >-
  Each binding identifies the assertions this suite executes; combined scenarios
  may require other bound suites. Existence is not a recorded execution result.
evidence:
  - >-
    services-accounting:modules/fiscal-close/tests/integration/services/persistence/period-close-runs.integration.spec.js
  - provenance: test
    source: >-
      services-accounting:modules/fiscal-close/tests/integration/services/persistence/period-close-runs.integration.spec.js
    assertion_titles:
      - 'fiscal close persistence: close runs (integration)'
      - creating a run
      - 'answers the queued run it created, requested by the caller now'
      - >-
        answers the same run, unchanged, for the same request with the same
        idempotency key
      - writes one run for the two requests
      - refuses the idempotency key reused for another period
      - 'refuses a second run of a period a run holds, whatever its kind'
      - generates the id of a run that names none
      - refuses a period the tenant does not have
      - refuses a business unit that is not the period’s
      - two requests with one idempotency key at once
      - makes the second request wait while the first holds the key
      - >-
        refuses the second request once the first commits, telling it to repeat
        the request
      - leaves the one run the first request wrote
      - moving a run
      - 'moves queued → running, recording the job’s id'
      - 'moves running → succeeded, recording when it finished'
      - lets a new run hold the period once its run has finished
      - 'moves queued → cancelled, recording when it finished'
      - 'refuses moving a finished run, before any statement'
      - refuses finishing a run that never started
      - >-
        refuses a move from a status the run is no longer in, telling the writer
        it changed
      - answers 404 for a run that does not exist
      - 'answers 404 for another tenant’s run, and leaves it as it was'
real_dependencies: >-
  Production persistence and mapping run with application-role transactions and
  workspace policies on PostgreSQL. Fixture records and fixed context values
  supply the inputs; the service and database enforcement under assertion remain
  real.
product_intent: proposed
implementation_evidence: observed
---
# Command identity, competing requests and run changes

## Verification Boundary

The suite checks its declared service or persistence boundary against local PostgreSQL. Bindings identify the assertions it contributes to a capability case; they do not establish every assertion in a combined case.

## What This Suite Proves

Persistence assertions cover matching and conflicting commands, active-run competition, insertion races, permitted run moves and stale expected status.

## What It Does Not Prove

This register records assertion scope without claiming a passing run or complete coverage of every rule and scenario variant.

## Real Dependencies and Test Doubles

Production persistence and mapping run with application-role transactions and workspace policies on PostgreSQL. Fixture records and fixed context values supply the inputs; the service and database enforcement under assertion remain real.

## Must Not Be Doubled

Keep production queries, writes, mappings, application-role privileges and database constraints real wherever they are the subject of an assertion. Recording financial ports establish invocation behavior; actual recognition and reversal require the suite using the real posting service.
