Skip to content

test(backend/shared): de-XML-ify stale compile/library-build suites - #918

Merged
thiagoralves merged 1 commit into
developmentfrom
fix/backend-shared-stale-tests
Jul 3, 2026
Merged

test(backend/shared): de-XML-ify stale compile/library-build suites#918
thiagoralves merged 1 commit into
developmentfrom
fix/backend-shared-stale-tests

Conversation

@thiagoralves

@thiagoralves thiagoralves commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #917 (which unblocked the unit-tests CI job). With the job now running, it surfaced three backend/shared suites that predate the XML/xml2st → in-process JSON-transpiler migration and never ran in CI, so they'd drifted against renamed/removed APIs.

  • compile/pipeline.test.tstranspileXmlToSttranspileToSt; assert the current { projectData } call contract (not the removed xml2stArgs); drop the dead XmlGenerator mock + obsolete XML-stage failure test; add a simulator-no-.hex edge test to hold the gate.
  • library/build-pipeline.test.ts — drop the XmlGenerator mock and the removed XML-generation / empty-data paths; assert prepareXmlForLibraryBuild's current { projectData, knownPous, manifest } | { error } contract.
  • library/library-build-orchestrator.test.ts — fake port uses transpileToSt({ projectData }, log); remove plc.xml intermediates/logs; restore coverage.

All three source files back to 100% functions/lines/statements (branches gate is 0). 95 tests pass (editor jest). Source untouched — test-only.

Not addressed: the VPP alias-sync failure (#4 in the earlier report) — left for separate triage per the maintainer.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved build-pipeline handling so failures are reported more consistently during translation, verification, and output generation.
    • Fixed cases where builds could appear successful even when required output was missing.
    • Strengthened cache and validation behavior to recover cleanly from unreadable or invalid stored data.

These suites predate the XML/xml2st → in-process JSON-transpiler migration and
never ran in CI (the unit-tests job was broken), so they drifted:
- compile/pipeline.test.ts: rename transpileXmlToSt→transpileToSt, assert the
  current {projectData} call contract, drop the dead XmlGenerator mock + XML
  stage test, add a simulator-no-binary edge test.
- library/build-pipeline.test.ts: drop the XmlGenerator mock and the removed
  XML-generation/empty-data paths; assert prepareXmlForLibraryBuild's current
  {projectData,knownPous,manifest}|{error} contract.
- library/library-build-orchestrator.test.ts: fake port uses transpileToSt
  ({projectData}, log); remove plc.xml intermediates/logs; restore coverage.

All three source files back to 100% funcs/lines/statements. 95 tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Test suites for the compile pipeline and library build pipeline/orchestrator are refactored to remove XmlGenerator/transpileXmlToSt mocking and instead mock/assert the transpileToSt port method. New failure-mode tests cover transpiler errors, missing hex/programSt outputs, verification-cache resilience, and .stlib write failures.

Changes

Test suite migration to transpileToSt

Layer / File(s) Summary
Compile pipeline mocks and happy path
src/backend/shared/compile/__tests__/pipeline.test.ts
Removes XmlGenerator mocking, reorganizes imports, and switches happy-path/validation-guard assertions from transpileXmlToSt to transpileToSt.
Compile pipeline failure and logging paths
src/backend/shared/compile/__tests__/pipeline.test.ts
Adds/adjusts failure-propagation, structured error, missing-hex, and log-streaming tests around transpileToSt.
Library prepareXmlForLibraryBuild contract
src/backend/shared/library/__tests__/build-pipeline.test.ts
Removes XmlGenerator mocking; updates success/failure assertions to expect projectData + knownPous instead of XML output.
Library orchestrator transpileToSt wiring
src/backend/shared/library/__tests__/library-build-orchestrator.test.ts
Introduces FAKE_PROGRAM_ST, extends PortHarness with transpile tracking, and updates canonical stage-order/abort-title expectations.
Library orchestrator resilience tests
src/backend/shared/library/__tests__/library-build-orchestrator.test.ts
Adds new tests for cache read/parse errors, IO errors, transpiler failures, verify-throw handling, and cache/.stlib write failures.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test as Test Harness
  participant Orchestrator as runLibraryBuildPipeline
  participant Port as LibraryBuildPort
  participant Cache as VerifyCache

  Test->>Orchestrator: run pipeline
  Orchestrator->>Port: prepareXmlForLibraryBuild
  Port-->>Orchestrator: projectData
  Orchestrator->>Port: transpileToSt(projectData, log)
  Port-->>Orchestrator: { ok: true, programSt: FAKE_PROGRAM_ST }
  Orchestrator->>Cache: compute MD5(FAKE_PROGRAM_ST), check cache
  Cache-->>Orchestrator: cache hit/miss
  Orchestrator-->>Test: stage events + result
Loading

Possibly related PRs

Suggested reviewers: Gustavohsdp

Poem

A rabbit hopped through mocks so old,
Traded XML for stories retold,
transpileToSt now leads the way,
Cache and .hex both tested today,
With paws crossed twice, the tests all pass — 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the test-suite refactor away from stale XML-based compile/library-build paths.
Description check ✅ Passed The description covers the follow-up context, affected suites, and main test updates, but it omits the template's Jira/DOD checklist sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/backend-shared-stale-tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@thiagoralves
thiagoralves merged commit 1a8365a into development Jul 3, 2026
11 of 12 checks passed
@thiagoralves
thiagoralves deleted the fix/backend-shared-stale-tests branch July 3, 2026 19:41

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/backend/shared/library/__tests__/library-build-orchestrator.test.ts (1)

174-184: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

arrayContaining doesn't verify stage order despite the test's intent.

The comment says "Stage messages flow through in order," but expect.arrayContaining only checks that all listed messages are present anywhere in the array — it ignores ordering and permits extra entries. This test can't catch a regression where stages fire out of sequence (e.g., transpile running after verification).

Consider filtering events down to just the messages under test and comparing with a plain toEqual (order-sensitive), or asserting index positions directly.

♻️ Suggested fix
-    expect(events.map((e) => e.message)).toEqual(
-      expect.arrayContaining([
-        'Starting library build...',
-        'Manifest OK — building "lib" v0.1.0.',
-        'Transpiling project to Structured Text',
-        'Verifying with OpenPLC Simulator (avr-gcc)...',
-        'Compiling library archive...',
-        'Library built successfully: build/lib.stlib',
-      ]),
-    )
+    const canonicalMessages = [
+      'Starting library build...',
+      'Manifest OK — building "lib" v0.1.0.',
+      'Transpiling project to Structured Text',
+      'Verifying with OpenPLC Simulator (avr-gcc)...',
+      'Compiling library archive...',
+      'Library built successfully: build/lib.stlib',
+    ]
+    expect(events.map((e) => e.message).filter((m) => canonicalMessages.includes(m))).toEqual(canonicalMessages)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/backend/shared/library/__tests__/library-build-orchestrator.test.ts`
around lines 174 - 184, The stage-order assertion in the library build
orchestrator test is too loose because library-build-orchestrator.test.ts uses
expect.arrayContaining on events.map((e) => e.message), which does not enforce
sequencing. Update the test around the events/message assertions to compare the
relevant messages with an order-sensitive check, or assert their relative
indices directly, so the flow through build stages is verified in the intended
order.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/backend/shared/library/__tests__/library-build-orchestrator.test.ts`:
- Around line 174-184: The stage-order assertion in the library build
orchestrator test is too loose because library-build-orchestrator.test.ts uses
expect.arrayContaining on events.map((e) => e.message), which does not enforce
sequencing. Update the test around the events/message assertions to compare the
relevant messages with an order-sensitive check, or assert their relative
indices directly, so the flow through build stages is verified in the intended
order.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 60115ac9-4d88-44fe-a82d-e17a27f3adfa

📥 Commits

Reviewing files that changed from the base of the PR and between 9da41ac and 78a38fb.

📒 Files selected for processing (3)
  • src/backend/shared/compile/__tests__/pipeline.test.ts
  • src/backend/shared/library/__tests__/build-pipeline.test.ts
  • src/backend/shared/library/__tests__/library-build-orchestrator.test.ts

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.

1 participant