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
117 lines
3.2 KiB
Python
117 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Tests for provider model-state persistence and migrations."""
|
|
|
|
from copy import deepcopy
|
|
from typing import Any
|
|
|
|
from qwenpaw.providers.provider_model_state import (
|
|
PROVIDER_SNAPSHOT_SCHEMA_VERSION,
|
|
migrate_provider_snapshot,
|
|
)
|
|
|
|
|
|
def test_migration_drops_legacy_placeholder_output_limit() -> None:
|
|
snapshot = {
|
|
"models": [
|
|
{
|
|
"id": "unknown-limit",
|
|
"name": "Unknown Limit",
|
|
"max_tokens": 8192,
|
|
},
|
|
],
|
|
}
|
|
|
|
assert migrate_provider_snapshot(snapshot) is True
|
|
|
|
model = snapshot["models"][0]
|
|
assert "max_tokens" not in model
|
|
assert "max_output_length" not in model
|
|
assert snapshot["snapshot_schema_version"] == (
|
|
PROVIDER_SNAPSHOT_SCHEMA_VERSION
|
|
)
|
|
assert migrate_provider_snapshot(snapshot) is False
|
|
|
|
|
|
def test_migration_preserves_non_placeholder_request_limit() -> None:
|
|
snapshot: dict[str, Any] = {
|
|
"custom_headers": {"X-Legacy": "kept"},
|
|
"models": [
|
|
{
|
|
"id": "configured-limit",
|
|
"name": "Configured Limit",
|
|
"max_tokens": 4096,
|
|
"generate_kwargs": {"temperature": 0.2},
|
|
"supports_image": True,
|
|
},
|
|
],
|
|
}
|
|
|
|
migrate_provider_snapshot(snapshot)
|
|
|
|
model = snapshot["models"][0]
|
|
assert model["generate_kwargs"] == {
|
|
"temperature": 0.2,
|
|
"max_tokens": 4096,
|
|
}
|
|
assert "max_output_length" not in model
|
|
assert model["supports_image"] is True
|
|
assert snapshot["custom_headers"] == {"X-Legacy": "kept"}
|
|
|
|
|
|
def test_migration_preserves_existing_generate_kwargs_limit() -> None:
|
|
snapshot: dict[str, Any] = {
|
|
"models": [
|
|
{
|
|
"id": "configured-limit",
|
|
"name": "Configured Limit",
|
|
"max_tokens": 4096,
|
|
"generate_kwargs": {"max_tokens": 2048},
|
|
},
|
|
],
|
|
}
|
|
|
|
migrate_provider_snapshot(snapshot)
|
|
|
|
model = snapshot["models"][0]
|
|
assert model["generate_kwargs"]["max_tokens"] == 2048
|
|
|
|
|
|
def test_migration_applies_to_extra_models_and_is_idempotent() -> None:
|
|
snapshot: dict[str, Any] = {
|
|
"extra_models": [
|
|
{
|
|
"id": "custom-limit",
|
|
"name": "Custom Limit",
|
|
"max_tokens": 4096,
|
|
},
|
|
],
|
|
}
|
|
|
|
assert migrate_provider_snapshot(snapshot) is True
|
|
|
|
model = snapshot["extra_models"][0]
|
|
assert model["generate_kwargs"]["max_tokens"] == 4096
|
|
migrated = deepcopy(snapshot)
|
|
assert migrate_provider_snapshot(snapshot) is False
|
|
assert snapshot == migrated
|
|
|
|
|
|
def test_discovered_model_migration_preserves_secret() -> None:
|
|
snapshot: dict[str, Any] = {
|
|
"api_key": "ENC:encrypted-provider-key",
|
|
"discovered_models": [
|
|
{
|
|
"id": "discovered-model",
|
|
"name": "Discovered Model",
|
|
"max_tokens": 4096,
|
|
},
|
|
],
|
|
}
|
|
|
|
assert migrate_provider_snapshot(snapshot) is True
|
|
|
|
model = snapshot["discovered_models"][0]
|
|
assert "max_tokens" not in model
|
|
assert model["generate_kwargs"]["max_tokens"] == 4096
|
|
assert snapshot["api_key"] == "ENC:encrypted-provider-key"
|