Skip to content

Reject automatic filesystem mocks in tests - #8866

Open
dmerand wants to merge 7 commits into
mainfrom
donald/lint-fs-automocks-20261011
Open

dmerand wants to merge 7 commits into
mainfrom
donald/lint-fs-automocks-20261011

Conversation

@dmerand

@dmerand dmerand commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

Automatic filesystem mocks hide file and directory behavior. Filesystem tests must use real temporary files so they can detect incorrect I/O.

WHAT is this pull request doing?

Enable @shopify/cli/no-filesystem-auto-mocks as an error and replace the seven existing automatic filesystem mocks with temporary files or call-observation spies on real implementations. Dev-session tests also wait for event processing to finish before they check results.

The rule covers automatic mocks only. Factory and partial mocks remain outside its scope. It also adds a rule pointer to the filesystem section of the testing guide.

No changeset is needed: this changes internal lint tooling and tests, not CLI behavior.

How to manually test your changes?

In an editor with ESLint diagnostics enabled, add vi.mock('@shopify/cli-kit/node/fs') to a test file. Confirm that the editor reports the automatic mock. Replace it with a factory mock, such as vi.mock('@shopify/cli-kit/node/fs', async () => ({...})), and confirm that the report is removed.

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing — I've identified the correct bump type (patch for bug fixes · minor for new features · major for breaking changes) and added a changeset with pnpm changeset add

@github-actions github-actions Bot added the no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. label Oct 11, 2026
@dmerand
dmerand marked this pull request as ready for review October 13, 2026 14:49
@dmerand
dmerand requested review from a team as code owners October 13, 2026 14:49
Copilot AI balanced review requested due to automatic review settings October 13, 2026 14:49

Copilot AI 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.

🟡 Changes recommended

Standard Vitest aliases, static template literals, and .spec.ts tests can bypass the new rule.

1 open finding
What changed in this PR

Adds lint enforcement against automatic filesystem mocks and migrates affected tests to real temporary files.

Changes:

  • Adds and enables no-filesystem-auto-mocks.
  • Reworks seven test suites around real filesystem behavior.
  • Documents the testing requirement.
File Description
packages/​eslint-plugin-cli/​rules/​no-filesystem-auto-mocks.js Implements the lint rule.
packages/​eslint-plugin-cli/​rules/​no-filesystem-auto-mocks.test.js Tests rule behavior.
packages/​eslint-plugin-cli/​index.js Exports the rule.
packages/​eslint-plugin-cli/​config.js Enables the rule as an error.
packages/​theme/​src/​cli/​utilities/​theme-command.test.ts Uses a temporary theme directory.
packages/​cli/​src/​cli/​commands/​docs/​generate.test.ts Writes generated interfaces under temporary directories.
packages/​cli-kit/​src/​public/​node/​doctor/​framework.test.ts Removes an unused filesystem mock.
packages/​cli-kit/​src/​public/​node/​context/​local.test.ts Tests executable detection with a real file.
packages/​cli-kit/​src/​public/​node/​api/​bulk-operations/​query.test.ts Tests queries with real files.
packages/​app/​src/​cli/​services/​dev/​processes/​dev-session/​dev-session-process.test.ts Uses real directories and deterministic async completion.
packages/​app/​src/​cli/​services/​dev/​processes/​app-logs-polling.test.ts Uses a real temporary logs directory.
docs/​cli/​testing-strategy.md Documents lint enforcement.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/eslint-plugin-cli/rules/no-filesystem-auto-mocks.test.js Outdated

@isaacroldan isaacroldan 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.

One gap in the automatic filesystem mock detection.


🤖 Generated by the review-pr skill

if (node.callee.type !== 'MemberExpression' || node.callee.computed) return
if (!['mock', 'doMock'].includes(node.callee.property.name)) return
if (!isVitestVi(context.sourceCode.getScope(node), node.callee.object)) return
if (node.arguments.length !== 1) return

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.

This skips automatic filesystem mocks with a second argument, like vi.mock('node:fs', {spy: false}), vi.mock('node:fs', {}), or vi.doMock('node:fs', undefined). I tried the {spy: false} case: lint passes, and readFileSync returns undefined for a real file with content. Can we check the second argument and add these cases to the rule tests, while keeping factories and {spy: true} allowed?


🤖 Generated by the review-pr skill

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants