Skip to content

Clear SonarCloud findings on main (quality gate and code smells) - #556

Merged
JE-Chen merged 52 commits into
mainfrom
dev
Nov 18, 2026
Merged

JE-Chen merged 52 commits into
mainfrom
dev

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Nov 17, 2026

Copy link
Copy Markdown
Member

Clears the SonarCloud findings on main after 1.2.2: the quality gate failure and the 271 new-code code smells.

Quality gate

The gate on main was ERROR on one condition, new_security_rating = 5, caused by one blocker vulnerability:
pythonsecurity:S2083 (path traversal) in examples/sync_workspace.py. The example now resolves the cache root
and reads the generated workspace.ini only when it is inside that cache (is_relative_to), otherwise it raises
ConfigSyncError. Output is unchanged.

Product code (69 findings)

  • S5754, 28 broad excepts: all deliberate cleanup boundaries, or outcomes handed to another thread or future, and
    all are re-raised later. Narrowing them would lose control signals such as asyncio's CancelledError, so each
    is annotated # NOSONAR beside its existing # reason:.
  • S2589, 4 "always true" conditions: identity re-checks after an await or close() that can replace the field.
    These are kept and annotated.
  • S1192, 11 duplicated literals: these became module constants.
  • S6546, 15 Union[...] hints: these became A | B. Built-in MCP tool schemas are explicit, so no schema
    changed; there are still 820 tools.
  • Smaller fixes:
    • redundant exception classes removed;
    • loop lambdas replaced with functools.partial;
    • a nested conditional extracted;
    • stop_resource now notes its label on the error it re-raises;
    • post_key still posts every UTF-16 unit;
    • one complex function split.

Tests (202 findings)

  • S9073: 162 composite assertions split into one condition per assert.
  • S5778: 35 pytest.raises blocks now contain only the call expected to raise.
  • S3415 / S9083 / S8714: operand order, an empty decorator call, and a try/except exception test.

Verification

  • Product code: 553 related test modules, 9,701 passed and 46 skipped. The typing contract passed with and
    without --extras, ruff and bandit are clean, and the complexity, broad-except and file-length gates pass.
  • Tests: the 50 changed test files, 922 passed and 5 skipped.

Records: docs/updates/2026-11-b.md, U-20261117-04 to -07.

Merging releases the next patch to PyPI through stable.yml.

SonarCloud's only vulnerability on main, the blocker failing its quality
gate, was a path read from the directory materialize_sync_profile returns.
The example now reads it only when it resolves inside the cache it made.
Justified broad excepts and post-await identity re-checks are annotated
where the reason already lives; duplicated labels became constants; the
smaller findings (redundant except classes, loop lambdas, a nested
conditional, an unused parameter, union syntax, one complex function) are
fixed without changing behaviour.
Composite assertions are split one condition per assert, pytest.raises
blocks keep only the call expected to raise, and three smaller test style
findings are fixed; every changed test still passes.
SonarCloud kept the path-traversal finding on read_bytes() into
write_bytes() despite the containment check; a file copy keeps the
generation's content out of the example entirely.
SonarCloud still read the list-then-all() form as a comprehension passed to
all(); an explicit loop keeps every UTF-16 unit posted after a failure.
With accept_viewer_audio_opus on, the host played an incoming viewer audio
track as soon as it arrived. A peer still waiting on the Accept/Reject
prompt could be heard on the host's speakers for as long as the prompt
stayed open, and audio played even with allow_audio off. The receiver now
asks an admission gate before every frame; the host gates on the same
authenticated-and-allow_audio rule the PCM mic channel uses.
absolute_path accepted anything is_absolute() did, including \host\share
and \.\pipe\ names. A profile pointing its config or image at a remote
share made the helper send the runtime account's NTLM credentials there,
and a pipe name connected to whoever created it first. Pinned paths now
have to be local drive paths without parent segments, the rule the browser
helper interpreter path already follows; the UI fixture image uses it too.
The image lease kept the file's bytes fixed, but CreateProcess resolves the
path again by name and the loader searches the image's directory for DLLs.
Another local account that could change an ancestor directory could swap in
a junction after the lease or plant a DLL beside the image, and the code ran
before the post-launch check noticed. The lease now refuses a path unless
every directory from the drive root down is a real directory no other
account may rename, delete, re-link, re-ACL or add files to, and the leased
handle's final path is the requested one.

Fixture children also start in the image's directory with an allow-listed
environment and a system-only PATH, so the host's API keys, tokens and user
PATH entries no longer reach them.
…r imports

ReadOnlyWorker._guard still took three arguments after NativeWorker started
passing the request and semantic flag, so a read-only helper raised
TypeError instead of refusing, and mypy rejected the override.

Scoped UIA checked the runtime before and after every COM call. The check
after one call and the one before the next had nothing between them, and
each is a durable write, so the managed UIA test ran past the 120 s
timeout on Windows. A check now follows every call, with one before the
first, which still separates any two native calls.

The Docker job installed je_auto_control_dev from PyPI over the image's
package, and helpers started with python -I ran that older copy. The job
now installs the mounted checkout in its place.
…full package

On Windows before Python 3.13, time.monotonic ticks every 15.6 ms, so a
stale capture, its acceptance and a new capture could share one timestamp
and the ordering and containment checks could not tell them apart. Every
producer and checker of capture timestamps now uses time.perf_counter,
which is the same clock on Linux and macOS.

je_auto_control_dev on PyPI is a snapshot without utils/agent_runtime.
Installing it in the Docker job overwrote the image's package, and helpers
started with python -I then failed to import their own module. The job now
installs the dev requirements without it.
The runtime checkpoints every read step with a durable write, and the
probe's 1 s default ran out on an ubuntu runner under load. This test
covers the read-apply-verify flow; reader deadlines have their own tests.
Captures are now ordered on time.perf_counter. The helper fixture still
stamped them with time.monotonic, which on Windows before Python 3.13 is
a different clock, so every capture looked outside the read request.
A UIA capture makes thousands of read-only COM calls, and each full
runtime checkpoint is a durable budget write plus authority queries, so a
managed observation still ran past the 120 s test timeout on a Windows
runner after the duplicate checks were removed. Every call now re-checks
the pinned task and owner, and the full checkpoint runs at most every
50 ms. The unthrottled checkpoint after the capture runs before anything
is published, so a revocation is still seen first.
@sonarqubecloud

Copy link
Copy Markdown

@JE-Chen
JE-Chen merged commit a6fe6ae into main Nov 18, 2026
55 of 56 checks passed
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.

1 participant