Skip to content

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

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

feat: allow aliases to be passed to ca transport#385
shihab-dls wants to merge 3 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 alias support so transports can register alternate PV names (including readback PV aliases).
  • Tests

    • Added and updated tests to verify alias registration and behavior, including readback alias suffix handling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Review Change Stack

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 49 minutes and 8 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: e76c4cf0-a28e-46fa-88c7-b9b5fe95b8aa

📥 Commits

Reviewing files that changed from the base of the PR and between 33ef1ff and 6a901c7.

📒 Files selected for processing (2)
  • tests/example_softioc.py
  • tests/transports/epics/ca/test_softioc_system.py
📝 Walkthrough

Walkthrough

Adds an aliases mapping to EpicsCAOptions, passes it from EpicsCATransport into EpicsCAIOC, and registers EPICS record aliases when creating read/write PVs; demo schema, tests, and example SoftIOC usage updated.

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; demo and test JSON schemas add the aliases property as an object of string values.
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; attribute PV wiring looks up per-PV aliases and forwards them into _create_and_link_read_pv/_create_and_link_write_pv, which register EPICS record aliases (readbacks get _RBV suffix when applicable).
Transport configuration wiring
src/fastcs/transports/epics/ca/transport.py
EpicsCATransport.connect() now passes self.epicsca.aliases to EpicsCAIOC on construction.
Tests and example updates
tests/..., tests/example_softioc.py
Adds tests asserting record.add_alias(...) is invoked for write and readback PVs; updates IOC construction and helper call sites to include the aliases parameter; example SoftIOC now configures epicsca.aliases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • coretl

Poem

🐰 With twitching nose and nimble paws I cheer,
Aliases hop in—now PVs appear!
Records named twice, both RBV and plain,
I nudge them gently—no values wane.
Hop, ADOdin, your twins are here!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: enabling aliases to be passed to the CA (EPICS Channel Access) transport.
Linked Issues check ✅ Passed The PR successfully implements alias support for FastCS PVs as required by #384, allowing configuration via transport options and PV aliasing in the IOC.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing alias support for the CA transport as specified in the linked issue; no out-of-scope modifications detected.

✏️ 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 (6a901c7).

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

Copy link
Copy Markdown
Contributor

@coretl coretl left a comment

Choose a reason for hiding this comment

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

Implementation looks fine.

Are there any system tests for CA? If so, then it should be added there too.

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

🤖 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.

Inline comments:
In `@tests/transports/epics/ca/test_softioc_system.py`:
- Around line 48-56: The test incorrectly expects the AliasB_RBV readback to
follow writes to the setpoint PV; update the assertion logic in this test (using
ctxt.get and pv_prefix symbols) to verify alias equivalence only — i.e., assert
AliasB and the canonical PV (:B) match each other and separately assert
AliasB_RBV equals the canonical RBV value as provided by the IOC, instead of
expecting AliasB_RBV to become 10 after ctxt.put(f"{pv_prefix}:B", 10); locate
the assertions that reference f"{pv_prefix}:B", f"{pv_prefix}:AliasB" and
f"{pv_prefix}:AliasB_RBV" and change them to compare aliases to the canonical PV
rather than asserting RBV propagation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 291df94c-4ca1-4430-895c-0ed54b09c8c4

📥 Commits

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

📒 Files selected for processing (3)
  • tests/example_softioc.py
  • tests/transports/epics/ca/test_softioc.py
  • tests/transports/epics/ca/test_softioc_system.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/transports/epics/ca/test_softioc.py

Comment thread tests/transports/epics/ca/test_softioc_system.py Outdated
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

2 participants