Skip to content

Srvb preview html#181

Merged
jfilak merged 3 commits into
jfilak:masterfrom
filak-sap:srvb_preview_html
Jul 6, 2026
Merged

Srvb preview html#181
jfilak merged 3 commits into
jfilak:masterfrom
filak-sap:srvb_preview_html

Conversation

@filak-sap

Copy link
Copy Markdown
Contributor

No description provided.

filak-sap added 3 commits July 6, 2026 20:01
The collection tag contains entity sets and associations and it is a
list.
To help with the future feature "preview html".
The feature was proposed by Michael Hoerisch.

I am not sure if it would it make more sense to make open browser
default but all the other command prints something to terminal.
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new srvb preview html CLI command to download or open the Fiori Launchpad preview page for OData V4 service bindings, changes ServiceInformation.collection to a list-node XML mapping, extends read output with entity sets/associations, and updates related tests and documentation.

Changes

SRVB Preview HTML Feature

Layer / File(s) Summary
ServiceInformation collection as list node
sap/adt/businessservice.py, test/unit/fixtures_adt_businessservice.py, test/unit/test_sap_adt_businessservice.py
ServiceInformation.collection changed from XmlNodeProperty to XmlListNodeProperty with default empty list and ServiceInformationCollection factory; fixtures gain additional collection entries and tests assert full deserialization.
Entity Sets and Associations listing
sap/cli/srvb.py, test/unit/test_sap_cli_srvb.py
read_object_text prints an "Entity Sets and Associations" section iterating service_information.collection; test assertions updated accordingly.
FEAP path encoding and preview html command
sap/cli/srvb.py, test/unit/fixtures_adt_businessservice.py, test/unit/test_sap_cli_srvb.py
Adds _encode_feap_path_params helper and preview_html command with --open flag, validates OData V4-only, builds encoded path/query params, opens browser or fetches/prints HTML; new fixtures and TestSRVBPreviewHtml cover V4 success, V2 error, and --open flows.
Documentation for preview html
doc/commands/srvb.md
Adds "preview html" to the sub-command list and a new subsection documenting usage, parameters, --open behavior, and OData V4-only support.

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

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI as sap.cli.srvb
  participant ADT as ODataV4ServiceGroup
  participant Connection

  User->>CLI: srvb preview html --service ...
  CLI->>ADT: fetch service binding/group
  ADT-->>CLI: service_information, entity sets
  CLI->>CLI: _encode_feap_path_params(...)
  alt --open flag
    CLI->>User: webbrowser.open(url)
  else default
    CLI->>Connection: execute('GET', path, params)
    Connection-->>CLI: html text
    CLI->>User: print(html)
  end
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided, so the intent cannot be assessed from the author text. Add a short description summarizing the new srvb preview html command and the related CLI/test updates.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately names the main change: adding srvb preview html support.
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 unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
test/unit/test_sap_cli_srvb.py (1)

389-397: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Flake8 E126: over-indented continuation line.

Static analysis flags these continuation lines as over-indented hanging indents.

Also applies to: 448-456

🤖 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 `@test/unit/test_sap_cli_srvb.py` around lines 389 - 397, The response fixture
formatting in the test setup has over-indented hanging continuation lines that
trigger Flake8 E126. Reformat the multi-line Response(...) calls in the affected
test blocks so the indentation of the continued arguments is consistent and
compliant, including the similar fixture setup near the other referenced block;
keep the logic unchanged and only adjust the indentation in the test helper
data.

Source: Linters/SAST tools

sap/cli/srvb.py (2)

275-287: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Bespoke path-encoding scheme could use a named constant and a note on the separator assumption.

The +20 shift is a magic number, and the ## separator is not validated against appearing inside service_url/entity_set/etc. Both are functionally verified by fixtures today, but a small constant plus a defensive comment would make this reverse-engineered encoding easier to maintain if SAP's own scheme changes.

♻️ Optional: extract the shift as a named constant
+# Code-point shift used by ADT's own web frontend when building the
+# encoded `feap/.../flp.html` path fragment.
+_FEAP_PATH_CODEPOINT_SHIFT = 20
+
 def _encode_feap_path_params(service_url, entity_set, service_name, service_version, group_name):
     ...
     components = [service_url, entity_set, '', '', service_name, service_version, group_name]
     params = "##".join(components)
-    encodedparams = "".join([chr(b) for b in [ord(c) + 20 for c in params]])
+    encodedparams = "".join(chr(ord(c) + _FEAP_PATH_CODEPOINT_SHIFT) for c in params)
     return urllib.parse.quote(encodedparams)
🤖 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 `@sap/cli/srvb.py` around lines 275 - 287, The _encode_feap_path_params helper
uses a magic +20 character shift and assumes the "##" separator will not appear
in any component, which makes the reverse-engineered encoding harder to
maintain. Update this function by extracting the shift into a clearly named
constant and adding a brief defensive comment near the components/join logic in
_encode_feap_path_params explaining the separator assumption and that it matches
the ADT-derived format.

323-341: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use a shared helper for the preview URL The --open branch still hand-concatenates the browser URL from connection._http_client._base_url and path, while the non-browser path goes through connection.execute(), which uses _build_adt_url(). A public preview-URL helper on Connection would keep both paths on one source of truth and avoid drift.

🤖 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 `@sap/cli/srvb.py` around lines 323 - 341, The preview URL is being assembled
manually in the `args.open_in_browser` branch instead of using the same shared
logic as `connection.execute()`, which can cause the browser path to drift. Add
a public preview-URL helper on `Connection` (or reuse `_build_adt_url()` through
a wrapper) and update `srvb.py` to call that helper when building the
`full_url`, keeping both preview flows on one source of truth.
🤖 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 `@sap/cli/srvb.py`:
- Around line 275-287: The _encode_feap_path_params helper uses a magic +20
character shift and assumes the "##" separator will not appear in any component,
which makes the reverse-engineered encoding harder to maintain. Update this
function by extracting the shift into a clearly named constant and adding a
brief defensive comment near the components/join logic in
_encode_feap_path_params explaining the separator assumption and that it matches
the ADT-derived format.
- Around line 323-341: The preview URL is being assembled manually in the
`args.open_in_browser` branch instead of using the same shared logic as
`connection.execute()`, which can cause the browser path to drift. Add a public
preview-URL helper on `Connection` (or reuse `_build_adt_url()` through a
wrapper) and update `srvb.py` to call that helper when building the `full_url`,
keeping both preview flows on one source of truth.

In `@test/unit/test_sap_cli_srvb.py`:
- Around line 389-397: The response fixture formatting in the test setup has
over-indented hanging continuation lines that trigger Flake8 E126. Reformat the
multi-line Response(...) calls in the affected test blocks so the indentation of
the continued arguments is consistent and compliant, including the similar
fixture setup near the other referenced block; keep the logic unchanged and only
adjust the indentation in the test helper data.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d5bb035f-a083-4f4d-97f0-686eadc1994e

📥 Commits

Reviewing files that changed from the base of the PR and between ce79be1 and 5e81a63.

📒 Files selected for processing (6)
  • doc/commands/srvb.md
  • sap/adt/businessservice.py
  • sap/cli/srvb.py
  • test/unit/fixtures_adt_businessservice.py
  • test/unit/test_sap_adt_businessservice.py
  • test/unit/test_sap_cli_srvb.py

@jfilak jfilak merged commit 9c0c291 into jfilak:master Jul 6, 2026
3 checks passed
@mhoerisch

Copy link
Copy Markdown
Contributor

Live-verified against an S/4HANA Public Cloud tenant (DDCI-flavor) on 2026-07-06. Combined with #182 into one test install.

sapcli srvb read now lists entity sets. Previously the read output stopped at the service URL; now it walks the service group's collection and enumerates the exposed entity sets:

$ sapcli srvb read ZSCLI_UITEST_B
Name        : ZSCLI_UITEST_B
Description : UI test binding
Package     : $TMP
Type        : ODATA
Version     : V4
Published   : true
Services:
  ZSCLI_UITEST_B (version 0001, NOT_RELEASED)
    URL: /sap/opu/odata4/sap/zscli_uitest_b/srvd/sap/zscli_uitest_b/0001/
    Entity Sets and Associations:
      FacetErr
      FacetOK
      StatA
      StatB

That alone closes a small papercut — before this PR the caller had to sapcli srvd read separately to discover the aliases.

sapcli srvb preview html works end-to-end on all four exposed entities. Each call fetches the full FLP-Sandbox HTML (4026 bytes wrapper — the SAPUI5 bootstrap that then loads the entity-specific OData metadata client-side). Verified for every entity of a test SRVB that carries four intentionally-different @UI.* configurations; each URL renders its own List Report + Object Page in an authenticated browser as expected.

URL construction is byte-identical to what ADT itself generates. I had reverse-engineered the FEAP plaintext layout independently on the same tenant (via decoding an ADT-generated URL with the inverse of feap_encode from a prior sapcli skill) and reached the same seven-component ##-joined layout your PR encodes. Comparing the plaintext produced by this PR against my known-working template:

/sap/opu/odata4/sap/zscli_uitest_b/srvd/sap/zscli_uitest_b/0001/##FacetOK######ZSCLI_UITEST_B##0001##ZSCLI_UITEST_B

Byte-for-byte match. The Caesar-shift-by-20 + URL-encode step is confirmed against the server-side decoder in the ABAP class CL_ADT_FEAP_ABSTRACT=>decode_feap_params (available on the tenant via sapcli class read).

Error paths behave cleanly:

$ sapcli srvb preview html ZSCLI_FINAL_V2UI Demo
Exception (SAPCliError):
  sapcli srvb preview html is currently supported only for OData V4 Service Bindings

$ sapcli srvb preview html ZSCLI_DOES_NOT_EXIST FacetOK
Exception (ExceptionResourceNotFound):
  Error while reading the object ZSCLI_DOES_NOT_EXIST from the database

--open also works — dispatches to Python's webbrowser module, tab opens in the default browser, no stdout, exit 0.

Great feature. Displaces a ~50-line manual URL-construction Python script we had been carrying as a plugin skill.

@mhoerisch mhoerisch mentioned this pull request Jul 6, 2026
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.

3 participants