Skip to content

fix: accept tagged Juju versions and type lists in the ops.testing consistency checker - #2857

Merged
tonyandrewmeyer merged 4 commits into
canonical:mainfrom
tonyandrewmeyer:fix/scenario-consistency-checker
Nov 9, 2026
Merged

tonyandrewmeyer merged 4 commits into
canonical:mainfrom
tonyandrewmeyer:fix/scenario-consistency-checker

Conversation

@tonyandrewmeyer

@tonyandrewmeyer tonyandrewmeyer commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Two small consistency checker fixes:

  • Context(juju_version='3.6-beta1') (or any tagged version) raised ValueError from the checker's int() parsing, even when the checks were being skipped. The version is now parsed with JujuVersion, with the skip check moved ahead of the parsing. A bare major version like '4', which the existing tests use, is still accepted.
  • An action parameter declared with a list of types, such as type: [string, "null"], raised TypeError (unhashable list) when the checker looked the type up. Each name in the list is now mapped, and null is understood, so a parameter can be checked as "a string or None".

…sts of action parameter types

A tagged juju_version such as 3.6-beta1 raised ValueError from the checker's
int() parsing, even when the checks were being skipped. The version is now
parsed with JujuVersion, after the skip check.

An action parameter declared with a list of types, such as [string, "null"],
raised TypeError when the checker looked the type up. Each name in the list is
now mapped, and "null" is understood.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@tonyandrewmeyer tonyandrewmeyer changed the title fix: Scenario consistency checker accepts tagged Juju versions and lists of action parameter types fix: accept tagged Juju versions and type lists in the ops.testing consistency checker Oct 26, 2026
tonyandrewmeyer and others added 3 commits November 5, 2026 01:29
Context(juju_version='4') has never worked, because ctx.run fails when it parses the version. Only direct callers of check_consistency could use it, and a malformed version reported a string with .0 on the end that the caller never wrote.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A parameter declared with a type the checker doesn't know was reported as missing from the action specification, which was false, and a parameter with no type got both errors. It is still inconsistent, as an unknown type is not valid JSON schema, but the error now says what is wrong.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cy checker

Flattening to a tuple treated the number in a tag as the patch, so 3.6-rc12 passed the 3.6.10 check for CloudSpec on Kubernetes, although it is before 3.6.0. JujuVersion gets the tag ordering right.

Also test that skipping the checks doesn't parse the version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tonyandrewmeyer
tonyandrewmeyer marked this pull request as ready for review November 8, 2026 22:35

@tromai tromai 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.

Thank you!

@tonyandrewmeyer
tonyandrewmeyer merged commit 8cbaac4 into canonical:main Nov 9, 2026
60 checks passed
@tonyandrewmeyer
tonyandrewmeyer deleted the fix/scenario-consistency-checker branch November 9, 2026 05:23
tonyandrewmeyer added a commit to tonyandrewmeyer/operator that referenced this pull request Dec 2, 2026
…consistency checker (canonical#2857)

Two small consistency checker fixes:

* `Context(juju_version='3.6-beta1')` (or any tagged version) raised
`ValueError` from the checker's `int()` parsing, even when the checks
were being skipped. The version is now parsed with `JujuVersion`, with
the skip check moved ahead of the parsing. A bare major version like
`'4'`, which the existing tests use, is still accepted.
* An action parameter declared with a list of types, such as `type:
[string, "null"]`, raised `TypeError` (unhashable list) when the checker
looked the type up. Each name in the list is now mapped, and `null` is
understood, so a parameter can be checked as "a string or `None`".

(cherry picked from commit 8cbaac4)

Backport notes: the 2.23 checker has always accepted a bare major version
such as '3' (and the existing tests use them), but JujuVersion doesn't, so
a bare major version is given a '.0' before parsing. The action parameter
check doesn't have the action_params variable on this branch, so it's added.
tonyandrewmeyer pushed a commit to tonyandrewmeyer/operator that referenced this pull request Dec 2, 2026
…nonical#2090)

Fixes canonical#2089

Juju allows actions to be declared using a shorthand.

Source `charmcraft.yaml`:
```
...
actions:
    add-secret:
```

Charmcraft pack produces this `actions.yaml` in the charm file:

```
add-secret: null
```

Juju is happy to deploy this charm, and call the action on the deployed
unit (without action arguments, obv.)

`ops[testing]` didn't like this.
This PR fixes state transition testing to treat a shorthand action as an
action without parameters.

(cherry picked from commit 733cd51)

Backport notes: canonical#2857 already added an action_params variable on this
branch, so the `or {}` is applied through an action_spec variable, as
main has it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tonyandrewmeyer added a commit that referenced this pull request Dec 3, 2026
…nch (#2964)

This cherry-picks fixes from main that were merged between the last
backport round (#2789) and 21 November:

* #2738: a non-leader touching its own application databag gets the "is
not leader" `RelationDataAccessError` on every access path, rather than
a bare `ModelError: permission denied`.
* #2780: an `_Abort(0)` from the charm's `__init__` (for example,
`load_config(errors='blocked')`) is treated as success in `ops.testing`,
as it is in production.
* #2787: `Context.trace_data` is no longer empty after the first
`Context` with opentelemetry-sdk 1.45.
* #2824: ops-tracing sends the correct OTLP span kind for spans that
aren't INTERNAL.
* #2847 and #2867: a `user-id` or `group-id` of 0 is kept in Pebble
services and exec checks.
* #2857: the consistency checker accepts tagged Juju versions (like
`3.6-beta1`) and action parameters with a list of types.
* #2877 and #2876: an error connecting the exec websockets cleans up
properly.
* #2875: errors reading the Pebble response are wrapped in
`ConnectionError`, so `Container.can_connect()` returns `False` rather
than raising when Pebble drops the connection.
* #2827: OTLP/JSON encoding of bytes and mapping attributes, and of
dropped attribute counts.
* #2870: exec output is decoded incrementally, so a multi-byte character
split across messages no longer raises.
* #2872: combining layers in Harness and Scenario keeps the check level,
and the original `override`, as Pebble does.
* #2871: `pull()` works with paths that have non-ASCII characters or
leading or trailing whitespace.
* #2855 (partly): `State(opened_ports=[ops.Port(...)])` works, and
Scenario ports compare equal to an equal `ops.Port`.
* #2917: `get_notices(types=...)` filters correctly in Harness and
`ops.testing`.
* #2901: `push()` escapes backslashes in the filename.

It also includes #2090, which was merged in October 2025 but never
backported: an action declared with the shorthand (no params or
description, so `null` in `actions.yaml`) no longer crashes the
consistency checker.

There were some adjustments, which are described in the individual
commit messages:

* #2780: on this branch, a non-zero `_Abort` is raised as is rather than
wrapped in `UncaughtCharmError`, so the new tests expect that. The
runtime's `_Abort(0)` handling also covers constructing the charm here,
so it now only swallows one once the `Ops` object exists (otherwise a
leaked `OPERATOR_DISPATCH` ended in an `AttributeError`). This branch
also doesn't have the framework close from #2541 when constructing the
charm fails, so `Ops` closes the framework itself after swallowing an
`_Abort(0)`.
* #2857: `JujuVersion` doesn't accept a bare major version like `'3'`,
but the checker on this branch always has (and the tests use them), so I
kept accepting those.
* #2855: I only ported the `ops.Port` and equality parts. The
duplicate-entity checks could start failing existing tests, which seems
wrong for a maintenance release. The other `State` fixes in #2855
(comparing unit IDs with `is not`, the shared default `BindAddress`, the
`deferred()` error message, and the `get_relation` docstring) aren't
included either. `State` only replaced `opened_ports` when the converted
list compared unequal, which the new equality defeats, so it now always
stores the converted ports.
* #2875: before Python 3.10, `socket.timeout` isn't a subclass of
`TimeoutError`, so it's checked for as well. Otherwise a timeout waiting
for Pebble's response became a plain `ConnectionError` on 3.8 and 3.9,
and `wait_change()` stopped retrying it.
* #2901: I left out the new `ValueError` for a path containing CR, LF,
or NUL. It isn't an `OSError` or a `pebble.Error`, so
`Container.push_path()` would stop collecting it and give up on the
remaining files. Those paths still get Pebble's `APIError`, as before.
`push()` only takes a `str` here, so the real Pebble tests (this one and
the #2871 one) pass `str(path)`.
* There's an extra commit that skips three of the #2827 tests when
opentelemetry-sdk drops bytes, mapping, and mixed-type list values
before the encoder sees them. The root lock on this branch has 1.34,
which does, so `tox -e coverage-tracing` failed. They still run under
`tracing/`.

#2738 can turn a charm's passing unit tests red, because Harness and
Scenario now raise for something production already did, so the 2.23.x
release notes should call it out. Something like:

> In Harness and `ops.testing`, a non-leader unit can no longer read its
own application databag with `in`, `len()` or iteration, or `update()`
it, matching what happens in production
([#2738](#2738)). Unit tests
that did this will now raise `RelationDataAccessError`.

I left out #2748 (it's built on the hookcmds-based error handling, so
would need rewriting), #2851 (`push_path` skipping symlinks is a
behaviour change), and #2878 (`CheckInfo.level` changes from `None` to
`UNSET`). Fixes merged after 21 November can go in the next round.

I've run `tox -e lint`, `static`, `unit`, `py3.8-unit`,
`coverage-tracing`, and `pebble` locally, as well as lint, static, and
unit in `tracing/`.

---------

Co-authored-by: James Garner <james.garner@canonical.com>
Co-authored-by: Gangavarapu Vivek <gangavarapu.0104@gmail.com>
Co-authored-by: Suyash Bhattarai <133975972+ItsM0rty@users.noreply.github.com>
Co-authored-by: Ben Hoyt <ben.hoyt@canonical.com>
Co-authored-by: nancy <singhnancy2004@gmail.com>
Co-authored-by: Matt Patchava <matt.patchava@canonical.com>
Co-authored-by: Indian-boult <64060864+Indian-boult@users.noreply.github.com>
Co-authored-by: Dima Tisnek <dima.tisnek@canonical.com>
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