Skip to content

fix(readiness): calculate Flow coverage the way Salesforce does - #59

Merged
mcarvin8 merged 2 commits into
mainfrom
feat/salesforce-coverage-formula
Nov 23, 2026
Merged

mcarvin8 merged 2 commits into
mainfrom
feat/salesforce-coverage-formula

Conversation

@mcarvin8

Copy link
Copy Markdown
Owner

What

sf flowcov readiness now calculates Flow coverage the way Salesforce does for "Deploy processes and flows as active".

  • Formula: Salesforce divides the Flow versions with coverage, both active ones and the latest inactive versions that have a test, by the active versions without coverage plus the versions with coverage. Before, readiness counted only active versions, so it could report less coverage than Salesforce uses. It was never more.
    • The new OrgCoverageSource.countCoveredInactiveVersions() counts the latest inactive versions of counted Flows that have coverage.
    • The headline, ready, and flowsNeeded now go by Salesforce's number. The JSON adds salesforceCoveragePercent and coveredInactiveVersions.
    • When the two numbers differ, the output shows both: Salesforce's figure first, then the active-only one. Otherwise it's the same one line as before.
  • Threshold: production sets the percentage in Process Automation Settings, so 75% isn't always right. When --threshold isn't passed, the report uses 75% and says so (thresholdAssumed in JSON). The flag help explains where to find the real value.
  • Element coverage: a note under the covered Flows says element coverage doesn't count toward the threshold, because a Flow counts once any test runs it.
  • Docs: the README's "How coverage is measured" section and the command help now describe the calculation and where the threshold is set.

Why

  • The formula: a Flow that's deployed inactive and then tested counts as covered for Salesforce, but not for readiness before this change.
  • The threshold and the note: a user saw "Flow coverage: 100%" next to Flows at 60–83% element coverage. They asked whether the requirement was per Flow, like Apex coverage. It isn't: it counts Flows, not elements, and the threshold can be something other than 75%.

Sources

  • The Salesforce help article Deploy Processes and Flows as Active gives the formula used here. Its worked example (10 covered versions over 1 active version without coverage plus 10 covered) comes to about 90%. This PR's tests reproduce that example.
  • The Tooling API FlowTestCoverage docs describe the calculation more loosely: covered Flows divided by active processes and autolaunched Flows. Taken literally, that can exceed 100% when inactive versions have coverage, so this PR follows the help article. Both sources count coverage on inactive versions as covered.

Testing

  • npm run build, npm run test and npm run lint:dependencies pass. Branch coverage is 98.76%.
  • New tests cover countCoveredInactiveVersions, the help article's example (90.9%), the assumed threshold, and the output wording.
  • Ran readiness against a scratch org: with no covered inactive versions, the output keeps the one-line form and adds the threshold and element coverage notes.

Salesforce also counts the latest inactive versions that have a test, so readiness could report
less coverage than Salesforce uses. readiness now applies Salesforce's formula for the headline,
ready, and Flows needed, shows the active-only figure when they differ, says when it assumed the
75% threshold that production can set, and notes that element coverage does not count.
@mcarvin8

Copy link
Copy Markdown
Owner Author

Added a README note from the Tooling API FlowTestCoverage docs. Apex tests run a Flow's active version, or its latest version when none is active, which is how inactive versions get coverage. Saving changes to a Flow version deletes its coverage.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/commands/flowcov/readiness.ts 97.82% <100.00%> (+0.04%) ⬆️
src/core/markdown.ts 100.00% <100.00%> (ø)
src/core/orgCoverageSource.ts 100.00% <100.00%> (ø)
src/core/readiness.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

🧬 Mutation Testing Results

Tested 5 changed file(s): src/commands/flowcov/readiness.ts, src/core/markdown.ts, src/core/orgCoverageSource.ts, src/core/readiness.ts, src/core/types.ts

🟢 Score: 91.03%  |  ✅ Killed: 538  |  ⚠️ Survived: 51  |  ⏱️ Timeout: 2  |  🚫 Ignored: 0

Per-file breakdown
File Score Killed Survived Timeout Ignored
src/commands/flowcov/readiness.ts 78.26% 90 25 0 0
src/core/markdown.ts 94.97% 189 10 0 0
src/core/orgCoverageSource.ts 91.88% 181 14 2 0
src/core/readiness.ts 97.50% 78 2 0 0

⚠️ Survived Mutants

src/commands/flowcov/readiness.ts:53:64 — StringLiteral

- 'api-version'
+ ""

src/commands/flowcov/readiness.ts:55:24 — StringLiteral

- 'Reading Flow coverage'
+ ""

src/commands/flowcov/readiness.ts:64:5 — CallExpression

- this.spinner.stop();
+ ;

src/commands/flowcov/readiness.ts:72:9 — LogicalOperator

- flags['fail-if-not-ready'] && !result.ready
+ flags['fail-if-not-ready'] || !result.ready

src/commands/flowcov/readiness.ts:83:9 — ConditionalExpression

- result.deployAsActive !== undefined
+ true

src/commands/flowcov/readiness.ts:87:11 — ConditionalExpression

- result.deployAsActive && !result.ready
+ true

src/commands/flowcov/readiness.ts:87:11 — LogicalOperator

- result.deployAsActive && !result.ready
+ result.deployAsActive || !result.ready

src/commands/flowcov/readiness.ts:91:50 — ConditionalExpression

- f.changes !== undefined
+ true

src/commands/flowcov/readiness.ts:91:25 — MethodExpression

- result.flows.some((f) => f.changes !== undefined)
+ result.flows.every(f => f.changes !== undefined)

src/commands/flowcov/readiness.ts:95:16 — StringLiteral

- 'Uncovered Flows'
+ ""

src/commands/flowcov/readiness.ts:110:16 — StringLiteral

- 'Covered Flows'
+ ""

src/commands/flowcov/readiness.ts:116:90 — StringLiteral

- ', '
+ ""

src/commands/flowcov/readiness.ts:119:7 — CallExpression

- this.log(ELEMENT_COVERAGE_NOTE);
+ ;

src/commands/flowcov/readiness.ts:122:9 — ConditionalExpression

- result.processBuilderProcesses > 0
+ true

src/commands/flowcov/readiness.ts:122:9 — EqualityOperator

- result.processBuilderProcesses > 0
+ result.processBuilderProcesses >= 0

src/commands/flowcov/readiness.ts:13:1 — CallExpression

- Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
+ ;

src/commands/flowcov/readiness.ts:26:13 — StringLiteral

- 'd'
+ ""

src/commands/flowcov/readiness.ts:28:15 — BooleanLiteral

- true
+ false

src/commands/flowcov/readiness.ts:27:16 — StringLiteral

- '.'
+ ""

src/commands/flowcov/readiness.ts:30:25 — ObjectLiteral

- {
      summary: messages.getMessage('flags.since.summary'),
    }
+ {}

src/commands/flowcov/readiness.ts:33:30 — ObjectLiteral

- {
      summary: messages.getMessage('flags.threshold.summary'),
      description: messages.getMessage('flags.threshold.description'),
      min: 0,
      max: 100,
    }
+ {}

src/commands/flowcov/readiness.ts:39:40 — ObjectLiteral

- {
      summary: messages.getMessage('flags.fail-if-not-ready.summary'),
      default: false,
    }
+ {}

src/commands/flowcov/readiness.ts:41:16 — BooleanLiteral

- false
+ true

src/commands/flowcov/readiness.ts:43:35 — ObjectLiteral

- {
      summary: messages.getMessage('flags.output-format.summary'),
      description: messages.getMessage('flags.output-format.description'),
      options: OUTPUT_FORMATS,
      default: 'human',
    }
+ {}

src/commands/flowcov/readiness.ts:47:16 — StringLiteral

- 'human'
+ ""

src/core/markdown.ts:39:86 — StringLiteral

- ', '
+ ""

src/core/markdown.ts:35:63 — StringLiteral

- ''
+ "Stryker was here!"

src/core/markdown.ts:55:21 — ConditionalExpression

- result.isSandbox === true
+ false

src/core/markdown.ts:58:9 — LogicalOperator

- result.deployAsActive && !result.ready
+ result.deployAsActive || !result.ready

src/core/markdown.ts:59:29 — StringLiteral

- ''
+ "Stryker was here!"

src/core/markdown.ts:77:55 — ArrayDeclaration

- ['Changes']
+ []

src/core/markdown.ts:77:56 — StringLiteral

- 'Changes'
+ ""

src/core/markdown.ts:116:13 — MethodExpression

- lines.join('\n').trimEnd()
+ lines.join('\n').trimStart()

src/core/markdown.ts:129:45 — EqualityOperator

- f.status === 'fail'
+ f.status !== 'fail'

src/core/markdown.ts:137:83 — StringLiteral

- ''
+ "Stryker was here!"

src/core/orgCoverageSource.ts:46:60 — MethodExpression

- items.slice(i, i + size)
+ items

src/core/orgCoverageSource.ts:51:42 — StringLiteral

- '\\\\'
+ ""

src/core/orgCoverageSource.ts:80:9 — ConditionalExpression

- flowNames.length === 0
+ false

src/core/orgCoverageSource.ts:94:9 — ConditionalExpression

- definitionByVersion.size === 0
+ false

src/core/orgCoverageSource.ts:122:90 — ArrayDeclaration

- []
+ ["Stryker was here"]

src/core/orgCoverageSource.ts:131:11 — EqualityOperator

- v.Status !== 'Active'
+ v.Status === 'Active'

src/core/orgCoverageSource.ts:134:11 — EqualityOperator

- idKey(v.Definition.LatestVersionId) === idKey(v.Id)
+ idKey(v.Definition.LatestVersionId) !== idKey(v.Id)

src/core/orgCoverageSource.ts:136:13 — BlockStatement

- {
      return undefined;
    }
+ {}

src/core/orgCoverageSource.ts:157:14 — OptionalChaining

- record?.Metadata
+ record.Metadata

src/core/orgCoverageSource.ts:158:13 — BlockStatement

- {
      return undefined;
    }
+ {}

src/core/orgCoverageSource.ts:216:46 — MethodExpression

- [...coveredNames].sort()
+ [...coveredNames]

src/core/orgCoverageSource.ts:227:9 — ConditionalExpression

- rows.length === 0
+ false

src/core/orgCoverageSource.ts:240:13 — BlockStatement

- {
      return undefined;
    }
+ {}

src/core/orgCoverageSource.ts:39:21 — StringLiteral

- 'Id, VersionNumber, ProcessType, Status, Definition.DeveloperName, Definition.NamespacePrefix'
+ ""

src/core/readiness.ts:75:8 — LogicalOperator

- b.changes ?? 0
+ b.changes && 0

src/core/readiness.ts:87:37 — ConditionalExpression

- counted === 0
+ false

@mcarvin8
mcarvin8 merged commit 2c90c35 into main Nov 23, 2026
21 checks passed
@mcarvin8
mcarvin8 deleted the feat/salesforce-coverage-formula branch November 23, 2026 22:17
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.

2 participants