Skip to content

feat: allow aliases to be passed to ca transport#385

Open
shihab-dls wants to merge 2 commits into
mainfrom
ca_aliases
Open

feat: allow aliases to be passed to ca transport#385
shihab-dls wants to merge 2 commits into
mainfrom
ca_aliases

Conversation

@shihab-dls
Copy link
Copy Markdown
Contributor

@shihab-dls shihab-dls commented May 28, 2026

Closes #384

This PR allows passing aliases to the ca transport. An Example would be:

transport:
  - epicsca:
      aliases:
         - PV_TO_ALIAS: "ALIAS"

Summary by CodeRabbit

  • New Features

    • Added EPICS CA aliases support, enabling users to configure alternative names for process variables through the transport configuration.
  • Tests

    • Enhanced test coverage for alias functionality, including readback PV alias handling.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Warning

Review limit reached

@shihab-dls, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 54 minutes and 39 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 80b86312-27f6-4987-a214-b75299c21f84

📥 Commits

Reviewing files that changed from the base of the PR and between 231f9b6 and 7e6acf7.

📒 Files selected for processing (1)
  • tests/transports/epics/ca/test_softioc.py
📝 Walkthrough

Walkthrough

This PR adds EPICS PV aliasing support to FastCS. A new aliases configuration field is added to EpicsCAOptions, threaded through EpicsCATransport to EpicsCAIOC, where aliases are looked up per PV and registered as EPICS record aliases. Tests verify alias registration for both write and readback PVs.

Changes

EPICS CA Aliases Support

Layer / File(s) Summary
Configuration contract and schema
src/fastcs/transports/epics/options.py, src/fastcs/demo/schema.json, tests/data/schema.json
EpicsCAOptions now includes an aliases: dict[str, str] field with a default empty dict. Both demo and test JSON schemas are updated to define the new aliases property as a string-valued object.
IOC alias support
src/fastcs/transports/epics/ca/ioc.py
EpicsCAIOC.__init__ accepts an aliases mapping and passes it to _create_and_link_attribute_pvs. Alias lookup for each PV is forwarded into read/write PV factory functions, which register EPICS record aliases when present (with special _RBV suffix handling for readback PVs).
Transport configuration wiring
src/fastcs/transports/epics/ca/transport.py
EpicsCATransport.connect() now passes self.epicsca.aliases to the EpicsCAIOC constructor during initialization.
Test implementation and updates
tests/transports/epics/ca/test_softioc.py
New tests verify write and readback PV alias registration behavior. Existing IOC constructor calls and helper invocations are updated to pass the aliases parameter.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • DiamondLightSource/fastcs#360: The main PR's EPICS CA "aliases" feature extends the already-refactored multi-controller EPICS CA IOC/PV wiring in src/fastcs/transports/epics/ca/ioc.py and passes new epicsca.aliases through src/fastcs/transports/epics/ca/transport.py, so it builds directly on the same PV-construction code paths introduced in the retrieved multi-controller PR.

Suggested reviewers

  • coretl

Poem

🐰 With whiskers twitching, I declare with glee,
Aliases now dance in harmony—
PVs linked and registered with care,
ADOdin finds its doubles there! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The changes implement alias support in FastCS [#384] with configuration via transport options, but lack evidence of testing with actual ADOdin equivalents. Verify that the implementation has been tested with relevant PVs aliased to ADOdin equivalents as specified in the acceptance criterion.
✅ 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 accurately summarizes the main change: allowing aliases to be passed to the CA transport.
Out of Scope Changes check ✅ Passed All changes directly support alias functionality: schema updates, transport options, IOC initialization, and PV creation with alias registration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ca_aliases

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.22%. Comparing base (c80a13c) to head (7e6acf7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #385      +/-   ##
==========================================
+ Coverage   91.20%   91.22%   +0.02%     
==========================================
  Files          72       72              
  Lines        2875     2882       +7     
==========================================
+ Hits         2622     2629       +7     
  Misses        253      253              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/fastcs/transports/epics/ca/ioc.py (1)

138-154: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

AttrRW ignores explicit readback alias keys.

Line 138 only looks up the write PV key, then reuses it for both records. A mapping like PREFIX:MyPv_RBV -> ... is never read for AttrRW, so that config is silently ignored.

Suggested fix (preserve fallback behavior, allow explicit RBV aliases)
-            alias = aliases.get(f"{pv_prefix}:{pv_name}", None)
+            write_alias = aliases.get(f"{pv_prefix}:{pv_name}")
+            read_alias = aliases.get(f"{pv_prefix}:{pv_name}_RBV", write_alias)
             match attribute:
                 case AttrRW():
@@
                         _create_and_link_read_pv(
-                            pv_prefix, f"{pv_name}_RBV", attr_name, alias, attribute
+                            pv_prefix, f"{pv_name}_RBV", attr_name, read_alias, attribute
                         )
                         _create_and_link_write_pv(
-                            pv_prefix, pv_name, attr_name, alias, attribute
+                            pv_prefix, pv_name, attr_name, write_alias, attribute
                         )
                 case AttrR():
                     _create_and_link_read_pv(
                         pv_prefix,
                         pv_name,
                         attr_name,
-                        alias,
+                        aliases.get(f"{pv_prefix}:{pv_name}"),
                         attribute,
                     )
                 case AttrW():
                     _create_and_link_write_pv(
-                        pv_prefix, pv_name, attr_name, alias, attribute
+                        pv_prefix, pv_name, attr_name, aliases.get(f"{pv_prefix}:{pv_name}"), attribute
                     )

@@
-    if alias:
-        suffix = "_RBV" if pv_name.endswith("_RBV") else ""
-        record.add_alias(f"{alias}{suffix}")
+    if alias:
+        alias_name = (
+            f"{alias}_RBV" if pv_name.endswith("_RBV") and not alias.endswith("_RBV") else alias
+        )
+        record.add_alias(alias_name)

Also applies to: 187-190

🤖 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/fastcs/transports/epics/ca/ioc.py` around lines 138 - 154, The AttrRW
branch currently only looks up the alias for the write PV and reuses it for the
readback, so explicit RBV alias keys (e.g. f"{pv_prefix}:{pv_name}_RBV") are
ignored; change the code to separately resolve an RBV alias with fallback to the
write alias (e.g. rbv_alias = aliases.get(f"{pv_prefix}:{pv_name}_RBV", alias))
and pass rbv_alias to _create_and_link_read_pv while passing alias to
_create_and_link_write_pv; apply the same pattern to the other AttrRW handling
block referenced (around lines 187-190) so explicit RBV alias keys are honored
but the previous fallback behavior remains.
tests/transports/epics/ca/test_softioc.py (1)

628-632: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix stale expected call signature in waveform test (currently breaks CI).

_create_and_link_read_pv now receives (pv_prefix, pv_name, attr_name, alias, attribute), but this assertion still expects the old 4-arg call.

Proposed test fix
     create_mock.assert_called_once_with(
-        DEVICE, "Waveform1d", "waveform_1d", api.attributes["waveform_1d"]
+        DEVICE, "Waveform1d", "waveform_1d", None, api.attributes["waveform_1d"]
     )
🤖 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 `@tests/transports/epics/ca/test_softioc.py` around lines 628 - 632, The test's
expected call signature is stale: _create_and_link_read_pv now takes (pv_prefix,
pv_name, attr_name, alias, attribute), but the assertion in
tests/transports/epics/ca/test_softioc.py still expects 4 args; update the
create_mock.assert_called_once_with invocation used after EpicsCAIOC([api], {})
to include the missing alias argument between the attr_name ("waveform_1d") and
the attribute (api.attributes["waveform_1d"]) — use the same alias value the
code passes (e.g., the alias string or None) so the assertion matches
_create_and_link_read_pv's new signature.
🧹 Nitpick comments (1)
src/fastcs/transports/epics/options.py (1)

36-40: ⚡ Quick win

Update EpicsCAOptions docstring; it’s now outdated.

Line 38 says this options class is currently empty, but Line 44 adds aliases. This can mislead users reading config docs.

Proposed docstring update
 class EpicsCAOptions:
     """Channel-Access-specific options.
 
-    Currently empty: present so ``epicsca:`` survives in fastcs.yaml as the
-    transport discriminator key. Reserved for future CA-specific knobs.
+    Channel-Access-specific options configured under ``epicsca:`` in fastcs.yaml.
+    ``aliases`` maps generated PV names to alias base names.
     """
🤖 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/fastcs/transports/epics/options.py` around lines 36 - 40, Update the
EpicsCAOptions class docstring to reflect that the class is not empty: mention
the added "aliases" attribute and briefly describe its purpose (e.g., mapping
alternate transport names to this transport) and any intended usage in
fastcs.yaml; edit the docstring in the EpicsCAOptions definition so it no longer
claims the class is currently empty and instead documents the aliases field and
its role for the epicsca transport discriminator.
🤖 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.

Outside diff comments:
In `@src/fastcs/transports/epics/ca/ioc.py`:
- Around line 138-154: The AttrRW branch currently only looks up the alias for
the write PV and reuses it for the readback, so explicit RBV alias keys (e.g.
f"{pv_prefix}:{pv_name}_RBV") are ignored; change the code to separately resolve
an RBV alias with fallback to the write alias (e.g. rbv_alias =
aliases.get(f"{pv_prefix}:{pv_name}_RBV", alias)) and pass rbv_alias to
_create_and_link_read_pv while passing alias to _create_and_link_write_pv; apply
the same pattern to the other AttrRW handling block referenced (around lines
187-190) so explicit RBV alias keys are honored but the previous fallback
behavior remains.

In `@tests/transports/epics/ca/test_softioc.py`:
- Around line 628-632: The test's expected call signature is stale:
_create_and_link_read_pv now takes (pv_prefix, pv_name, attr_name, alias,
attribute), but the assertion in tests/transports/epics/ca/test_softioc.py still
expects 4 args; update the create_mock.assert_called_once_with invocation used
after EpicsCAIOC([api], {}) to include the missing alias argument between the
attr_name ("waveform_1d") and the attribute (api.attributes["waveform_1d"]) —
use the same alias value the code passes (e.g., the alias string or None) so the
assertion matches _create_and_link_read_pv's new signature.

---

Nitpick comments:
In `@src/fastcs/transports/epics/options.py`:
- Around line 36-40: Update the EpicsCAOptions class docstring to reflect that
the class is not empty: mention the added "aliases" attribute and briefly
describe its purpose (e.g., mapping alternate transport names to this transport)
and any intended usage in fastcs.yaml; edit the docstring in the EpicsCAOptions
definition so it no longer claims the class is currently empty and instead
documents the aliases field and its role for the epicsca transport
discriminator.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2da62478-6221-49d5-8c10-f756644d25ab

📥 Commits

Reviewing files that changed from the base of the PR and between c80a13c and 231f9b6.

📒 Files selected for processing (6)
  • src/fastcs/demo/schema.json
  • src/fastcs/transports/epics/ca/ioc.py
  • src/fastcs/transports/epics/ca/transport.py
  • src/fastcs/transports/epics/options.py
  • tests/data/schema.json
  • tests/transports/epics/ca/test_softioc.py

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.

Alias PVs to ADOdin

1 participant