Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Regression: concurrent credential writes must not lose entries.
|
|
|
|
Review #7081 Issue 1: a fresh ``AsyncCredentialStore`` per call site meant
|
|
each instance had its own RLock, so two concurrent read-modify-write cycles
|
|
(AnySearch auto-registration racing a Console save) could each ``os.replace``
|
|
the whole YAML, silently dropping the other writer's entry.
|
|
|
|
The store is now a process-level singleton keyed by canonical path; this
|
|
test widens the read-modify-write window and verifies both refs survive.
|
|
"""
|
|
# pylint: disable=protected-access
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import time
|
|
|
|
import pytest
|
|
|
|
from qwenpaw.drivers.credentials.store import AsyncCredentialStore
|
|
from qwenpaw.drivers.credentials.types import CredentialRecord
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_same_path_instances_are_shared(tmp_path) -> None:
|
|
path = tmp_path / "credentials.yaml"
|
|
assert AsyncCredentialStore(path) is AsyncCredentialStore(path)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_concurrent_writes_preserve_both_refs(tmp_path) -> None:
|
|
path = tmp_path / "credentials.yaml"
|
|
store_a = AsyncCredentialStore(path)
|
|
store_b = AsyncCredentialStore(path)
|
|
|
|
# Widen the read-modify-write window so a lost update would be
|
|
# deterministic if the instances did not share a lock.
|
|
original_write = AsyncCredentialStore._write_root
|
|
|
|
def slow_write(instance, data) -> None:
|
|
time.sleep(0.05)
|
|
return original_write(instance, data)
|
|
|
|
AsyncCredentialStore._write_root = slow_write # type: ignore[assignment]
|
|
try:
|
|
await asyncio.gather(
|
|
store_a.put(
|
|
CredentialRecord(
|
|
ref="tool/a",
|
|
kind="static",
|
|
secrets={"api_key": "a"},
|
|
),
|
|
),
|
|
store_b.put(
|
|
CredentialRecord(
|
|
ref="tool/b",
|
|
kind="static",
|
|
secrets={"api_key": "b"},
|
|
),
|
|
),
|
|
)
|
|
finally:
|
|
AsyncCredentialStore._write_root = original_write
|
|
|
|
refs = await store_a.list_refs()
|
|
assert "tool/a" in refs
|
|
assert "tool/b" in refs
|
|
assert await store_a.get("tool/a") is not None
|
|
assert await store_a.get("tool/b") is not None
|