Skip to content

bug(#632): wrong-test-order lint#784

Merged
yegor256 merged 12 commits intoobjectionary:masterfrom
h1alexbel:632
Dec 27, 2025
Merged

bug(#632): wrong-test-order lint#784
yegor256 merged 12 commits intoobjectionary:masterfrom
h1alexbel:632

Conversation

@h1alexbel
Copy link
Copy Markdown
Member

@h1alexbel h1alexbel commented Nov 22, 2025

In this pull I've implemented new lint: wrong-test-order, that issues defect with warning severity if test attributes are wrongly ordered.

see #632

Summary by CodeRabbit

  • New Features

    • Added a lint that warns when unit tests are placed before live objects (reports warning with contextual info).
  • Documentation

    • Added guidance illustrating correct vs incorrect test ordering with examples.
  • Tests

    • Added multiple test cases covering correct order, no tests, single/multiple tests, mixed orders, and wrong-order detection.
  • Chores

    • CI: gated optional jobs via RUN_WORKFLOW, updated Java matrix, added cleanup step, increased job timeout.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 22, 2025

Walkthrough

Adds a new XSLT lint rule detecting unit tests placed before live objects, accompanying documentation and multiple YAML test cases (allowed and violating orders), and updates CI workflows to gate certain jobs via a RUN_WORKFLOW variable and adjust the Maven JDK matrix and exclusions.

Changes

Cohort / File(s) Summary
Lint rule (XSLT)
src/main/resources/org/eolang/lints/tests/wrong-test-order.xsl
New XSLT stylesheet that locates unit nodes whose names start with + and whose following sibling is not a +‑prefixed unit, emitting <defect> entries with line, optional context (when line=0), severity="warning", and message: "The unit test wrongly ordered: <escaped-name>".
Documentation
src/main/resources/org/eolang/motives/tests/wrong-test-order.md
New Markdown describing that unit tests must appear after live objects, with EO examples of incorrect and correct ordering.
Test resources — allowed
src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-correct-order.yaml, src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-no-tests.yaml, src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-single-test.yaml, src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-tests-only.yaml
Added YAML test cases asserting zero or specific warnings for correct arrangements of tests and live objects using the new stylesheet.
Test resources — violations
src/test/resources/org/eolang/lints/packs/single/wrong-test-order/catches-mixed.yaml, src/test/resources/org/eolang/lints/packs/single/wrong-test-order/catches-test-first.yaml, src/test/resources/org/eolang/lints/packs/single/wrong-test-order/catches-wrong-order.yaml
Added YAML test cases asserting detection of wrong test ordering, with assertions on defect counts, severities, and specific line numbers.
CI workflows
.github/workflows/hone.yml, .github/workflows/jmh.yml, .github/workflows/mvn.yml, .github/workflows/deep.yml
Introduced top-level RUN_WORKFLOW variable and replaced if: false with if: ${{ vars.RUN_WORKFLOW == 'true' }} for conditional jobs; updated mvn.yml matrix to use Java 17 and 23 (replacing 11 and 21), added OS/JDK exclusions, added a cleanup step; increased deep job timeout from 20 to 30 minutes.

Sequence Diagram(s)

sequenceDiagram
    participant EO as EO Source (XML)
    participant XSLT as XSLT Processor
    participant Sheet as wrong-test-order.xsl
    participant Defects as Defects (XML)

    EO->>XSLT: parse source XML
    XSLT->>Sheet: apply stylesheet
    Sheet->>Sheet: find unit nodes with name starting "+"
    Sheet->>Sheet: inspect following sibling

    alt Violation (test before live object)
        Sheet->>Defects: emit <defect line="..." severity="warning">The unit test wrongly ordered: ...</defect>
    else No violation
        Note right of Sheet: no defect emitted
    end

    Defects-->>XSLT: return defects document
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review XSLT XPath selectors, escaping, and context/line handling.
  • Verify YAML asserts match expected defect outputs and line numbers.
  • Confirm CI matrix exclusions and the intent of RUN_WORKFLOW gating.

Suggested reviewers

  • maxonfjvipon
  • yegor256

Poem

I hop through XML rows and leaves,
I sniff where plus-marked testing weaves,
When tests arrive before the play,
I mark the fault and point the way,
A rabbit lints with joyful heaves 🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main change: implementation of a new 'wrong-test-order' lint that checks for incorrectly ordered test attributes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c190a69 and 8292612.

📒 Files selected for processing (2)
  • .github/workflows/deep.yml (1 hunks)
  • .github/workflows/mvn.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/mvn.yml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: mvn (windows-2022, 23)
  • GitHub Check: mvn (ubuntu-24.04, 17)
  • GitHub Check: reserved
  • GitHub Check: mvn (ubuntu-24.04, 23)
  • GitHub Check: deep
  • GitHub Check: ort
🔇 Additional comments (1)
.github/workflows/deep.yml (1)

15-15: Verify the timeout increase is necessary and proportional.

The timeout was increased from 20 to 30 minutes (50% increase) to accommodate new lint tests. Confirm that the new test additions actually require this buffer by checking whether:

  • Local test runs show build times consistently approaching or exceeding 20 minutes with the new tests
  • 30 minutes provides sufficient headroom without over-provisioning
  • Other affected workflows (hone.yml, jmh.yml, mvn.yml) need similar adjustments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-correct-order.yaml (1)

1-13: Test logic is correct, but the filename is semantically misleading.

The test correctly detects a violation (test on line 3 followed by live object on line 4), but the filename allows-correct-order.yaml suggests it's validating correct ordering. Consider renaming to catches-live-after-test.yaml or similar to better reflect the violation scenario being tested.

src/test/resources/org/eolang/lints/packs/single/wrong-test-order/catches-wrong-order.yaml (1)

1-12: Test logic is correct, but the filename is semantically misleading.

The test correctly expects no violations when the code contains only live objects (no +> test units). However, the filename catches-wrong-order.yaml suggests the test detects a violation, when it actually validates the absence of violations. Consider renaming to allows-no-tests.yaml or validates-live-objects-only.yaml for clarity. (Note: allows-no-tests.yaml already exists; consider naming based on the distinction if intentional.)

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 973a154 and 93ce4b8.

📒 Files selected for processing (9)
  • src/main/resources/org/eolang/lints/tests/wrong-test-order.xsl (1 hunks)
  • src/main/resources/org/eolang/motives/tests/wrong-test-order.md (1 hunks)
  • src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-correct-order.yaml (1 hunks)
  • src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-no-tests.yaml (1 hunks)
  • src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-single-test.yaml (1 hunks)
  • src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-tests-only.yaml (1 hunks)
  • src/test/resources/org/eolang/lints/packs/single/wrong-test-order/catches-mixed.yaml (1 hunks)
  • src/test/resources/org/eolang/lints/packs/single/wrong-test-order/catches-test-first.yaml (1 hunks)
  • src/test/resources/org/eolang/lints/packs/single/wrong-test-order/catches-wrong-order.yaml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: ort
  • GitHub Check: mvn (macos-15, 21)
  • GitHub Check: mvn (ubuntu-24.04, 21)
  • GitHub Check: qulice
  • GitHub Check: mvn (windows-2022, 21)
  • GitHub Check: mvn (macos-15, 11)
  • GitHub Check: mvn (windows-2022, 11)
  • GitHub Check: mvn (ubuntu-24.04, 11)
  • GitHub Check: deep
  • GitHub Check: reserved
🔇 Additional comments (12)
src/main/resources/org/eolang/motives/tests/wrong-test-order.md (1)

1-19: Documentation is clear and well-structured.

The examples effectively illustrate the rule: unit tests (marked with +>) must follow live objects (marked with >). The structure and formatting align well with the test cases that validate this lint.

src/test/resources/org/eolang/lints/packs/single/wrong-test-order/catches-test-first.yaml (1)

1-13: Test structure and assertions are correct.

The test properly validates detection of a test unit appearing before a non-test unit. The assertions and input accurately reflect the violation being tested.

src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-no-tests.yaml (1)

1-12: Test correctly validates no violations when tests are absent.

This edge case ensures the lint properly handles code containing only live objects without false positives.

src/test/resources/org/eolang/lints/packs/single/wrong-test-order/catches-mixed.yaml (1)

1-13: Test correctly handles mixed test/non-test ordering.

The scenario with interleaved tests and non-tests is properly validated, flagging the first violation at line 2.

src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-single-test.yaml (1)

1-10: Test validates the edge case of a single test with no following sibling.

Properly confirms that the lint accepts a test unit when it has no subsequent siblings to create an ordering violation.

src/test/resources/org/eolang/lints/packs/single/wrong-test-order/allows-tests-only.yaml (1)

1-11: Test validates correct consecutive test ordering.

The scenario with multiple tests grouped together and following live objects is properly validated, confirming no violations are flagged for this correct pattern.

src/main/resources/org/eolang/lints/tests/wrong-test-order.xsl (6)

1-5: LGTM!

Standard XML declaration and copyright header are properly formatted.


11-11: LGTM!

The output declaration is correctly configured for XML output.


12-14: LGTM!

The template structure and XPath selection logic correctly identify test objects (those with names starting with '+'). The use of //o will traverse all depths, which is appropriate for this lint rule.


15-16: LGTM!

The logic correctly identifies ordering violations by checking if a test object (name starting with '+') is followed by a non-test object. The use of following-sibling::*[1] ensures only the immediate next sibling is checked, which is the right approach for detecting ordering issues.


17-29: LGTM!

The defect element construction is well-structured with appropriate attributes (line number, optional context for line 0, and warning severity).


30-31: Unable to locate the eo:escape-plus function definition to verify the double escaping intent.

The function eo:escape-plus is imported from /org/eolang/parser/_funcs.xsl, which does not exist in this repository's source. This suggests the function is provided by an external dependency. The eo:escape function itself performs XML escaping (quotes and spaces).

The double escaping pattern eo:escape(eo:escape-plus(@name)) is used consistently in two locations (wrong-test-order.xsl:31 and unit-test-without-phi.xsl:29), and escape-plus is also used independently in incorrect-test-object-name.xsl:16, which suggests the behavior is intentional. However, without access to the escape-plus definition, the exact sequence of transformations cannot be verified.

Optional grammar improvement: Line 30 message "The unit test wrongly ordered:" could be more concise as "Unit test is wrongly ordered:" or "Unit test is in wrong order."

@github-actions github-actions bot added the core Changes are made to core parts of the code base label Nov 22, 2025
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93ce4b8 and 26f8e6c.

📒 Files selected for processing (2)
  • .github/workflows/hone.yml (2 hunks)
  • .github/workflows/jmh.yml (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: actionlint
.github/workflows/jmh.yml

[error] 16-16: context "env" is not allowed here. available contexts are "github", "inputs", "needs", "vars". see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details

.github/workflows/hone.yml

[error] 24-24: context "env" is not allowed here. available contexts are "github", "inputs", "needs", "vars". see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: reserved
  • GitHub Check: deep
  • GitHub Check: mvn (windows-2022, 11)
  • GitHub Check: mvn (macos-15, 11)
  • GitHub Check: mvn (ubuntu-24.04, 11)
  • GitHub Check: mvn (windows-2022, 21)
  • GitHub Check: mvn (ubuntu-24.04, 21)
  • GitHub Check: ort

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/mvn.yml (1)

20-24: Clarify platform-specific Java 17 exclusions and add inline documentation.

The exclusion of Java 17 from windows-2022 and macos-15 is unusual, as Java is officially cross-platform. This suggests either:

  • Known compatibility issues with these runners that warrant exclusion, or
  • A temporary workaround that should be revisited.

Without inline documentation, future maintainers may not understand the rationale. Consider adding a comment explaining why Java 17 is excluded on these platforms (e.g., hardware limitations, toolchain incompatibilities, known JVM bugs).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ad0891 and 93a551e.

📒 Files selected for processing (1)
  • .github/workflows/mvn.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: mvn (windows-2022, 23)
  • GitHub Check: mvn (ubuntu-24.04, 23)
  • GitHub Check: mvn (ubuntu-24.04, 17)
  • GitHub Check: ort
  • GitHub Check: reserved
  • GitHub Check: deep
🔇 Additional comments (2)
.github/workflows/mvn.yml (2)

19-19: Verify Java version upgrade rationale.

The Java matrix was changed from [11, 21] to [17, 23], completely removing Java 21 (the current LTS version). Java 23 is a non-LTS release (released Sept 2024), which is unusual as a primary CI test target. Before merging, confirm:

  1. Is Java 21 (LTS) intentionally no longer supported?
  2. Why test Java 23 (non-LTS) instead of the current LTS (21)?
  3. Does this align with the project's Java support policy?

1-38: PR scope clarification: Lint rule implementation not visible in this file.

The PR objectives mention implementing a new wrong-test-order lint rule, but this file contains only CI workflow configuration updates (Java version and platform exclusions). If the lint rule implementation is in other files, ensure those files are also included in the review scope. If this is the only change, verify alignment between the PR title and actual changes.

@h1alexbel
Copy link
Copy Markdown
Member Author

@maxonfjvipon take a look, please

@h1alexbel
Copy link
Copy Markdown
Member Author

@yegor256 take a look, please

@h1alexbel h1alexbel requested a review from yegor256 December 27, 2025 11:46
@yegor256 yegor256 merged commit 6f39bb6 into objectionary:master Dec 27, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes are made to core parts of the code base

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants