Skip to content

Fix/optics serve var resolution - #343

Open
kun-codes wants to merge 3 commits into
mozarkai:mainfrom
kun-codes:fix/optics-serve-var-resolution
Open

kun-codes wants to merge 3 commits into
mozarkai:mainfrom
kun-codes:fix/optics-serve-var-resolution

Conversation

@kun-codes

Copy link
Copy Markdown
Member

Bishwa Bhusan Saha added 2 commits July 9, 2026 17:43
…tion

- adds a whole-param `${name}` resolver to `utils.py`, using an anchored regex (`^\$\{([^}]+)\}$`) rather than the loose `startswith`/`endswith` check used elsewhere. This distinguishes a param that *is* a single variable reference from one that merely embeds `${var}` inside a larger expression (e.g. `${a} + ${b}`), which must be left untouched for keywords like `Evaluate`/`Condition` to resolve internally
…ecutor`

- `optics serve`'s single-keyword execution path (`KeywordExecutor.execute`) passed params straight through with no `${var}` resolution at all, unlike CSV/YAML execution and `optics live`, which both do this generically. As a result, most keywords (anything not implementing its own internal resolution, e.g. `press_element`, `execute_module`, `date_evaluate`) received `${var}` completely unresolved when called over the HTTP API.

- resolve each param via `utils.resolve_scalar_param` before dispatch, skipping indices a keyword marks via `@raw_params` so keywords that manage their own substitution (`Evaluate`, `Condition`, etc.) are unaffected.
Copilot AI review requested due to automatic review settings July 9, 2026 12:16

Copilot AI 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.

Pull request overview

This PR centralizes ${var} parameter resolution for keyword execution (notably for optics serve) by resolving whole-parameter variable references from session.elements before dispatching to keyword methods, while allowing keywords to mark certain argument positions as “raw” and skip auto-resolution.

Changes:

  • Added resolve_scalar_param utility to resolve whole-parameter ${name} references from session.elements.
  • Updated KeywordExecutor.execute to pre-resolve parameters (respecting _raw_param_indices) before deserializing and invoking keyword methods.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
optics_framework/common/utils.py Adds a helper to resolve whole ${var} references against session.elements for use by execution paths.
optics_framework/common/execution.py Resolves parameters before keyword dispatch (with raw-index opt-out) so optics serve can correctly substitute variables.
Comments suppressed due to low confidence (1)

optics_framework/common/execution.py:192

  • KeywordExecutor.execute wraps all exceptions (including OpticsError) into OpticsError(Code.E0401), which discards the original structured error code/details (e.g. element/variable resolution errors from resolve_scalar_param). Prefer re-raising OpticsError unchanged so callers can handle the specific code, while still wrapping unexpected exceptions.
            except Exception as e:
                await event_manager.publish_event(Event(
                    entity_type="keyword",
                    entity_id=session.session_id,
                    name=self.keyword,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread optics_framework/common/utils.py Resolved
Comment thread optics_framework/common/utils.py Resolved
@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

@malto101

malto101 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Hello @kun-codes
could you explain the PR?

what is it solving?
how are you fixing?

@kun-codes

Copy link
Copy Markdown
Member Author

@malto101 Currently when passing a variable like ${var} to a keyword in optics serve, it doesn't get resolved to the value of the variable. Instead it is passed literally like "${var}". This resolution of variables is present for the csv execution and optics live. My pr adds it to optics serve too

@malto101

Copy link
Copy Markdown
Member

@malto101 Currently when passing a variable like ${var} to a keyword in optics serve, it doesn't get resolved to the value of the variable. Instead it is passed literally like "${var}". This resolution of variables is present for the csv execution and optics live. My pr adds it to optics serve too

Got it!.
does optics serve support CRUD elements/Modules/TC

This branch has not been deployed

No deployments
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