Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/packages-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
pnpm install --frozen-lockfile

- name: Check package contracts before building release assets
run: pnpm contracts:check && pnpm format:check && pnpm lint && pnpm type-check
run: pnpm check:static

- name: Verify managed package versions
run: |
Expand Down
8 changes: 5 additions & 3 deletions docs/40-deployment/local-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ pdm run python -m inkcre_extension_registry

修改模型后运行 `pnpm db:makemigrations`,审查生成的迁移。Tortoise 1.1 的 `CreateModel` 不会把 `Meta.constraints` 写入数据库,因此新表的 CHECK 约束须使用原生 `AddConstraint` 操作显式添加,参照初始迁移;真实 PostgreSQL 的非法数据验收用于防止约束仅存在于模型描述中。`pnpm db:migrate` 只向前执行;上线后只能追加迁移,修复通过后续迁移完成。交付必须以 `MIGRATION_DATABASE_URL` 指定 owner 连接,服务的 `DATABASE_URL` 使用普通 `registry_app`。本地单账号开发仍可省略迁移变量并复用 `DATABASE_URL`。权限迁移创建 NOLOGIN 角色;生产和预览控制器在迁移后通过 `scripts/registry_database.py` 设置独立密码并启用登录。服务不在请求或启动期间迁移。

完整检查需要空的、一次性的 PostgreSQL 数据库:
`pnpm check:static` 检查源码、样式和生成契约,可以在准备数据库前运行。完整门禁和包发布 CI 复用此入口。绑定校验在临时目录运行生成器,`pnpm contracts:generate` 用于有意更新契约时写回工作树。

完整检查需要全新的、一次性的 PostgreSQL 实例:

```bash
REGISTRY_TEST_DATABASE_URL=postgres://registry:registry-check@localhost:5432/registry_check pnpm check
```

CI 创建 PostgreSQL 17 service;本地使用独立、一次性的 PostgreSQL 实例或 Neon 测试分支。授权迁移会创建实例级角色,因此仅在共享实例内增加一个空数据库不足以隔离这些检查。不得指向共享开发、PR 预览或生产库。验收运行真实迁移,检查模型漂移,通过真实 ORM / PostgreSQL 和本地 Moto S3 服务验证发布、重试、并发冲突、失败回滚、私有分页、文档条件替换与快照域隔离、blocked 读取、GET / HEAD 和 ETag 重验证。迁移使用 owner,业务验收使用 `registry_app`,并验证创建表、修改业务表、写迁移记录和创建角色均被拒绝。D1 导入验收使用临时 SQLite 快照,比较所有逻辑字段的内容摘要。测试仅在空库插入测试记录,并在退出时清理;失败可能保留 schema 和迁移记录,目标库仍须属于一次性验证生命周期。
CI 创建 PostgreSQL 17 service。本地每次运行都使用新的独立 PostgreSQL 实例或 Neon 测试分支,数据库编码使用 UTF-8。授权迁移会创建实例级角色,因此共享实例里的空数据库也无法隔离这些检查。验收先只读检查公开 schema 和 `registry_app` 角色,然后用含历史发行和文档数据的夹具回放升级。事务、并发上传冲突、Simple 索引、目录回跳、文档生命周期和 HTTP 缓存行为经过真实 ORM、PostgreSQL 和本地 Moto S3。迁移使用 owner,业务验收使用 `registry_app`,并验证创建表、修改业务表、写迁移记录和创建角色均被拒绝。D1 导入验收使用临时 SQLite 快照,比较所有逻辑字段的内容摘要。运行后会保留迁移和角色,供 CI 随后的服务镜像验收使用。再次运行须重建实例。

`pnpm registry:check` 单独执行上述验收,仍需要同一个测试变量。CI 另外拒绝修改或删除已在 base 中存在的迁移,并构建完整服务镜像。测试数据不会写入共享预览。

Registry 通过不可变 Git commit 安装 `InKCre/ui` 的 `@inkcre/ui-web` 公共 Sass 包。修改 `web/registry.scss` 后运行 `pnpm web:build`;生成 CSS 提交到源码,并由 `pnpm web:check` 比对。模板、CSS 和 JavaScript 都随 Python wheel 打包。视觉验收覆盖空态、详情版本选择、Publisher、键盘操作、窄屏和明暗主题。

Toolkit、Core Runtime 与 Web Runtime 保持各自的版本和发布机制。`pnpm build` 构建这些独立产物;Registry 的容器部署不会发布它们,也不会引入单独的前端部署流程。 Web Runtime 的 Core SDK 开发依赖使用官方预构建 GitHub Release tgz,完整性记录在 pnpm 锁文件中;构建无需跨仓检出源码或运行 SDK 准备脚本。

`pnpm packages:check` 在构建后创建独立虚拟环境,通过 wheel metadata 解析安装 Registry 与本次 Toolkit 候选,再执行 `pip check` 和服务 import;它不加载 workspace 源码,防止可编辑安装掩盖错误依赖边界。该检查需要包索引访问并随 `pnpm check` 运行。Registry 的文档 API 要求 Toolkit `>=0.5,<0.6`。Python 改动在所属 project 的 `.changes/` 记录 Towncrier fragment;Web Runtime 使用 `.changeset/`。合并普通改动后,Version PR 才准备版本与 changelog,正式产物只从准备完成的 `main` 发布。
`pnpm packages:check` 在构建后创建独立虚拟环境,安装候选 Registry、Toolkit 和 Python Runtime wheel,再执行 `pip check` 和服务 import。验收用安装后的 Toolkit CLI 生成文档和静态目录,Python Runtime 从该目录的本地 HTTP Simple 索引通过标准 pip 下载并安装精确发行。该检查需要包索引访问并随 `pnpm check` 运行。Registry 的文档 API 要求 Toolkit `>=0.5,<0.6`。Python 改动在所属 project 的 `.changes/` 记录 Towncrier fragment;Web Runtime 使用 `.changeset/`。合并普通改动后,Version PR 才准备版本与 changelog,正式产物只从准备完成的 `main` 发布。

本次独立原生发行与 Peer 参与模型需要先生成候选 SDK 版本才能跨仓验证:Registry 0.3、Toolkit 0.5、Python Runtime 0.2 由既有 `scripts/release.py prepare` 生成,Web Runtime 0.4 由 Changesets 生成,相关 intents 已消费,后续不能再次升版。PR 58 使用维护者授予的 `coordinated-sdk-version-preparation` label 声明同一 PR 内包含功能与机械版本准备。CI 监听 label 添加/移除并从 PR metadata 决定是否传递 `--allow-feature-version-preparation`;日志显示该用途。这个开关只解除行为文件分类限制,仍要求版本/changelog 一致、版本前进、对应 fragments 已消费及全部质量检查。无 label 默认保持原有严格规则。本地完整验收使用 `BASE_REVISION=<base SHA> RELEASE_CHECK_ARGS=--allow-feature-version-preparation pnpm check`。

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"scripts": {
"build": "SOURCE_DATE_EPOCH=315532800 pdm build --no-sdist --dest \"$INIT_CWD/dist\" && SOURCE_DATE_EPOCH=315532800 pdm build --project toolkit --no-sdist --no-clean --dest \"$INIT_CWD/dist\" && SOURCE_DATE_EPOCH=315532800 pdm build --project runtimes/core-py --no-sdist --no-clean --dest \"$INIT_CWD/dist\" && pnpm --filter @inkcre/extension-runtime-web build",
"changeset": "changeset",
"check": "pnpm release:check && pnpm web:check && pnpm contracts:check && pnpm format:check && pnpm lint && pnpm type-check && pnpm build && pnpm --filter @inkcre/extension-runtime-web exec node check-boundaries.mjs && pnpm packages:check && pnpm registry:check",
"check": "pnpm release:check && pnpm check:static && pnpm build && pnpm --filter @inkcre/extension-runtime-web exec node check-boundaries.mjs && pnpm packages:check && pnpm registry:check",
"check:static": "pnpm web:check && pnpm contracts:check && pnpm format:check && pnpm lint && pnpm type-check",
"packages:check": "pdm run python scripts/check_packages.py",
"contracts:check": "pdm run python scripts/generate_contracts.py --check && pdm run python runtimes/core-py/scripts/generate_contracts.py --check && pnpm --filter @inkcre/extension-runtime-web check:bindings",
"contracts:generate": "pdm run python scripts/generate_contracts.py && pdm run python runtimes/core-py/scripts/generate_contracts.py && pnpm --filter @inkcre/extension-runtime-web generate:bindings",
Expand Down
8 changes: 3 additions & 5 deletions runtimes/web/check-boundaries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ try {
['2.0.0-beta.1', '1.10.0', '1.2.0'],
)
assert.equal(preferredPublishedRelease(catalogReleases).version, '1.10.0')
assert.equal((await releases.getRelease('inkcre/catalog', '1.10.0', true)).version, '1.10.0')
assert.equal(
(await releases.get('inkcre/catalog', '1.10.0', true)).distribution,
'module_federation',
)
const exact = await releases.get('inkcre/catalog', '1.10.0', true)
assert.equal(exact.version, '1.10.0')
assert.equal(exact.module_federation.manifest_url, `${origin}/mf-manifest.json`)
const originalGet = ExtensionParticipationModel.get
const selection = {
name: 'inkcre/catalog',
Expand Down
31 changes: 31 additions & 0 deletions runtimes/web/generate-bindings.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { execFileSync, spawnSync } from 'node:child_process'
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'

const check = process.argv.includes('--check')
const bindings = 'src/generated'
const output = check ? mkdtempSync(join(tmpdir(), 'inkcre-web-bindings-')) : bindings

try {
execFileSync('openapi-ts', ['-f', 'openapi-ts.config.ts', '--output', output, '--no-log-file'], {
stdio: 'inherit',
})
execFileSync('prettier', ['--config', '../../.prettierrc.json', '--write', output], {
stdio: 'inherit',
})
if (check) {
const diff = spawnSync('git', ['diff', '--no-index', '--name-only', '--', bindings, output], {
stdio: 'inherit',
})
if (diff.error) throw diff.error
if (diff.status !== 0) {
console.error(
'Web Runtime bindings differ. Run pnpm contracts:generate at the workspace root.',
)
process.exitCode = diff.status ?? 1
}
}
} finally {
if (check) rmSync(output, { recursive: true, force: true })
}
4 changes: 2 additions & 2 deletions runtimes/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"prepare": "pnpm build",
"build": "tsdown --platform neutral",
"check:boundaries": "pnpm build && node check-boundaries.mjs",
"check:bindings": "pnpm generate:bindings && git diff --exit-code -- src/generated",
"generate:bindings": "openapi-ts -f openapi-ts.config.ts && prettier --write src/generated",
"check:bindings": "node generate-bindings.mjs --check",
"generate:bindings": "node generate-bindings.mjs",
"type-check": "tsc --noEmit",
"pack": "pnpm pack"
},
Expand Down
4 changes: 0 additions & 4 deletions scripts/check_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@
def check_content_sites() -> None:
"""Configuration must keep each snapshot on its own valid content origin."""
for management, content, accepted in (
("https://registry.example.com", "https://{snapshot}.docs.example.com", True),
("https://registry.example.co.uk", "https://{snapshot}.docs.example.co.uk", True),
("https://registry.example.com", "https://{snapshot}.exampleusercontent.net", True),
("https://registry.team.github.io", "https://{snapshot}.docs.team.github.io", True),
("https://registry.team.github.io", "https://{snapshot}.other.github.io", True),
("https://registry.example.com", "https://registry-docs-{snapshot}.example.com", True),
("https://registry.example.com", "https://docs.registry-{snapshot}.example.com", False),
("http://localhost", "http://{snapshot}.docs.localhost", True),
("https://registry.example.com", "http://{snapshot}.docs.localhost", False),
):
with patch.dict(
Expand Down Expand Up @@ -141,7 +138,6 @@ async def upload(payload, content=zipped, expected=200, headers=None, scope="glo
first_response = await upload(first)
assert "etag" not in first_response.headers
first_record = first_response.json()
assert (await upload(first)).json() == first_record
assert (await request("GET", private, headers=authorization)).json()["sets"][0][
"snapshot_id"
] == first["snapshot_id"]
Expand Down
80 changes: 80 additions & 0 deletions scripts/check_installed_runtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""Run inside the isolated wheel environment against the Toolkit's HTTP preview output."""

import asyncio
import json
import sys
import tempfile
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import Mock
from urllib.request import urlopen

from inkcre_extension_runtime_core_py import (
ExtensionEnvironmentApplicationRequiredError,
ExtensionManager,
ExtensionRegistryError,
)
from inkcre_extension_runtime_core_py.distribution import (
AcquiredDistribution,
PipDistributionConsumer,
)
from inkcre_extension_runtime_core_py.release import (
RegistryReleaseClient,
require_python_association,
)


def main(origin: str) -> None:
def read(path: str) -> bytes:
with urlopen(origin + path, timeout=10) as response:
return response.read()

assert json.loads(read("/v2/extensions")) == [
{"name": "check/catalog", "nickname": "Catalog check"}
]
detail = json.loads(read("/v2/extensions/check/catalog/distributions/module_federation"))
remote = detail["releases"][0]
assert remote["name"] == "check/catalog" and remote["version"] == "1.10.0"
manifest = json.loads(read(remote["module_federation"]["manifest_url"]))
prefix = "/extensions/check/catalog/1.10.0/module-federation/"
assert manifest["metaData"]["publicPath"] == origin + prefix
assert read(prefix + "remoteEntry.js") == b"export const check = true;"

name, version, host = "check/catalog", "1.2.3", "1.0.0"
catalog = RegistryReleaseClient(origin)
try:
catalog.get(name, "1.10.0")
except ExtensionRegistryError as error:
assert "different exact Release" in str(error)
else:
raise AssertionError("Python Runtime accepted a Release with a different coordinate")
release = catalog.get(name, version)
association = require_python_association(release, host)
selection = SimpleNamespace(name=name, distribution="python", version=version, enabled=False)
store = Mock()
store.get_participation.return_value = selection
manager = ExtensionManager(
store, {name: selection}, peer_id="check", registry_origin=origin, host_version=host
)

consumer = PipDistributionConsumer(origin)
with tempfile.TemporaryDirectory(prefix="extension-download-") as directory:
wheel = consumer.download(release, association, host, Path(directory))
try:
asyncio.run(manager.enable(name))
except ExtensionEnvironmentApplicationRequiredError:
pass
else:
raise AssertionError(
"Downloading a wheel must leave the running Peer unable to enable it"
)
store.set_participation_enabled.assert_not_called()
assert AcquiredDistribution.discover(name, version, host) is None

installed = consumer.apply(wheel, release, association, host)
assert installed.entry_point.load().marker == "preview wheel"
print("Installed Python Runtime applied the exact wheel from the preview Simple index.")


if __name__ == "__main__":
main(sys.argv[1])
Loading