Skip to content

Check and fix mock names in pre-commit hook - #464

Open
cameron-craig-etas wants to merge 6 commits into
eclipse-score:mainfrom
etas-contrib:check-mock-naming
Open

Check and fix mock names in pre-commit hook#464
cameron-craig-etas wants to merge 6 commits into
eclipse-score:mainfrom
etas-contrib:check-mock-naming

Conversation

@cameron-craig-etas

@cameron-craig-etas cameron-craig-etas commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

#422

This PR adds a Python script to validate test doubles (mocks, stubs, fakes etc.), to ensure they use the test double name as a prefix (e.g mock_component.cpp). We recently updated all our mocks to use a consistent format (/pull/457). This pre-commit will keep things nice and tidy 🧹

As far as testing goes I have ran through these scenarios manually:

  • Attempting to commit a mock with a backwards name:
    Check and fix test double file names.....................................Failed
    - hook id: test-doubles-naming-fix
    - exit code: 1
    - files were modified by this hook
    
    WARNING: Non-conformant files have been found, fixing now.
    WARNING: Renaming: score/launch_manager/src/daemon/src/process_group_manager/details/component_mock.hpp -> score/launch_manager/src/daemon/src/process_group_manager/details/mock_component.hpp.
    
  • Attempting to commit a stub with a backwards name:
    Check and fix test double file names.....................................Failed
    - hook id: test-doubles-naming-fix
    - exit code: 1
    - files were modified by this hook
    
    WARNING: Non-conformant files have been found, fixing now.
    WARNING: Renaming: bad_stub.hpp -> stub_bad.hpp.
    
  • Attempting to commit a mock stub mutant hybrid:
    Check and fix test double file names.....................................Failed
    - hook id: test-doubles-naming-fix
    - exit code: 1
    
    Traceback (most recent call last):
      File "/home/crc1yok/git/lifecycle/./scripts/fix_test_doubles_naming_precommit.py", line 236, in <module>
        raise SystemExit(main())
                       ^^^^^^
      File "/home/crc1yok/git/lifecycle/./scripts/fix_test_doubles_naming_precommit.py", line 201, in main
        operations = define_operations(args.filenames)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/crc1yok/git/lifecycle/./scripts/fix_test_doubles_naming_precommit.py", line 136, in define_operations
        raise ValueError(
    ValueError: Invalid file name mock_fake.hpp contains multiple double names.
    
  • A valid commit with no changes to test doubles
    Check and fix copyright headers with cr_checker..........................Passed
    

@cameron-craig-etas cameron-craig-etas changed the title Check mock names in pre-commit hook Check an fix mock names in pre-commit hook Aug 13, 2026
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

License Check Results

🚀 The license check job ran with the Bazel command:

bazel run --lockfile_mode=error //:license-check

Status: ⚠️ Needs Review

Click to expand output
[License Check Output]
Extracting Bazel installation...
Starting local Bazel server (8.6.0) and connecting to it...
INFO: Invocation ID: 44bdde01-cfae-496c-b982-e5225fa02024
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Loading: 
Loading: 0 packages loaded
Loading: 0 packages loaded
Loading: 0 packages loaded
    currently loading: 
Loading: 0 packages loaded
    currently loading: 
Loading: 0 packages loaded
    currently loading: 
Loading: 0 packages loaded
    currently loading: 
Loading: 0 packages loaded
    currently loading: 
Analyzing: target //:license-check (1 packages loaded, 0 targets configured)
Analyzing: target //:license-check (1 packages loaded, 0 targets configured)

Analyzing: target //:license-check (43 packages loaded, 10 targets configured)

Analyzing: target //:license-check (106 packages loaded, 56 targets configured)

Analyzing: target //:license-check (154 packages loaded, 3153 targets configured)

Analyzing: target //:license-check (158 packages loaded, 9012 targets configured)

Analyzing: target //:license-check (163 packages loaded, 9345 targets configured)

Analyzing: target //:license-check (170 packages loaded, 9397 targets configured)

Analyzing: target //:license-check (171 packages loaded, 9521 targets configured)

INFO: Analyzed target //:license-check (175 packages loaded, 11535 targets configured).
[12 / 16] JavaToolchainCompileClasses external/rules_java+/toolchains/platformclasspath_classes; 0s disk-cache, processwrapper-sandbox ... (2 actions running)
[14 / 16] JavaToolchainCompileBootClasspath external/rules_java+/toolchains/platformclasspath.jar; 0s disk-cache, processwrapper-sandbox
INFO: Found 1 target...
Target //:license.check.license_check up-to-date:
  bazel-bin/license.check.license_check
  bazel-bin/license.check.license_check.jar
INFO: Elapsed time: 26.148s, Critical Path: 2.37s
INFO: 16 processes: 12 internal, 3 processwrapper-sandbox, 1 worker.
INFO: Build completed successfully, 16 total actions
INFO: Running command line: bazel-bin/license.check.license_check ./formatted.txt <args omitted>
usage: org.eclipse.dash.licenses.cli.Main [-batch <int>] [-cd <url>]
       [-confidence <int>] [-ef <url>] [-excludeSources <sources>] [-help] [-lic
       <url>] [-project <shortname>] [-repo <url>] [-review] [-summary <file>]
       [-timeout <seconds>] [-token <token>]

@github-actions

Copy link
Copy Markdown

The created documentation from the pull request is available at: docu-html

@cameron-craig-etas cameron-craig-etas changed the title Check an fix mock names in pre-commit hook Check and fix mock names in pre-commit hook Aug 14, 2026
@cameron-craig-etas
cameron-craig-etas marked this pull request as ready for review August 14, 2026 07:05

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

Mostly nit picks

Comment thread README.md
SPDX-License-Identifier: Apache-2.0
----------------------------------------------------------------------------- -->

# bad_mock.hpp

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.

Think this was added by mistake

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, good spot

Comment thread .pre-commit-config.yaml
- id: test-doubles-naming-fix
name: Check and fix test double file names
entry: python3 ./scripts/fix_test_doubles_naming_precommit.py
language: system

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.

Suggested change
language: system
language: python

"""
suffix = "".join(path.suffixes)
if suffix:
return path.name[: -len(suffix)], suffix

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.

I think you can use path.stem, instead of path.name[: -len(suffix)]

FAKE = "fake"

@staticmethod
def from_path(path: Path):

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.

Suggested change
def from_path(path: Path):
def from_path(path: Path) -> 'TestDoubleName':

You can use '' to type hint something that isn't "accessible".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Aaaah brilliant, I was wondering how to do that. Brilliant :)

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants