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
1 change: 1 addition & 0 deletions .changes/browser-delivery-verification.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
支持从工作树和 CI 验收 Registry 实际交付的 Module Federation 扩展,记录三个仓库的候选版本。
66 changes: 60 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
description: Exact InKCre/impl-py commit for Registry-to-Peer acceptance
required: false
type: string
browser_revision:
description: Exact InKCre/impl-ts commit for MF acceptance instead of the Python Peer check
required: false
type: string

permissions:
contents: read
Expand All @@ -23,15 +27,18 @@ concurrency:

jobs:
cross-repository-peer:
name: Registry publication and Python Peer installation
if: github.event_name == 'workflow_dispatch' && inputs.core_revision != ''
name: Registry extension acceptance
if: github.event_name == 'workflow_dispatch' && (inputs.core_revision != '' || inputs.browser_revision != '')
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- name: Require an exact Core commit
- name: Require exact consumer commits
env:
CORE_REVISION: ${{ inputs.core_revision }}
run: test "${#CORE_REVISION}" -eq 40 && [[ "$CORE_REVISION" =~ ^[0-9a-f]+$ ]]
BROWSER_REVISION: ${{ inputs.browser_revision }}
run: |
[[ "$CORE_REVISION" =~ ^[0-9a-f]{40}$ ]]
[[ -z "$BROWSER_REVISION" || "$BROWSER_REVISION" =~ ^[0-9a-f]{40}$ ]]

- name: Checkout Registry
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -57,12 +64,59 @@ jobs:
with:
python-version-file: registry/.python-version

- name: Verify Registry publication and Peer restart
- name: Install locked Registry dependencies
working-directory: registry
run: |
python -m pip install -r requirements-pdm.txt
pdm install --frozen-lockfile
pdm run registry:verify-peer ../core

- name: Verify Registry publication and Peer restart
if: inputs.browser_revision == ''
working-directory: registry
run: pdm run registry:verify-peer ../core --extension local_files

- name: Checkout the exact Web Host and MF producer
if: inputs.browser_revision != ''
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: InKCre/impl-ts
ref: ${{ inputs.browser_revision }}
path: browser
persist-credentials: false

- name: Install the browser consumer's pnpm
if: inputs.browser_revision != ''
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
with:
package_json_file: browser/package.json

- name: Set up the browser consumer's Node
if: inputs.browser_revision != ''
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: browser/package.json
cache: pnpm
cache-dependency-path: browser/pnpm-lock.yaml

- name: Install Web workspace and Chromium
if: inputs.browser_revision != ''
working-directory: browser
run: |
pnpm install --frozen-lockfile
pnpm exec playwright install --with-deps chromium

- name: Verify MF publication and browser loading
if: inputs.browser_revision != ''
working-directory: registry
run: pdm run registry:verify-browser ../browser ../core

- name: Upload browser and disposable database failure evidence
if: failure() && inputs.browser_revision != ''
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: registry-browser-acceptance
path: browser/test-results/
if-no-files-found: ignore

dependency-review:
name: Dependency review
Expand Down
20 changes: 17 additions & 3 deletions docs/40-deployment/local-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,24 @@ pdm run registry:verify-peer ../impl-py
仅迭代 Registry 时,可以传入 `--core-receipt /path/to/receipt.json` 复用同一 daemon 上的 Core 镜像。
在 Python 工作树运行 `pdm run core:candidate > receipt.json` 取得该文件。

`--extension local_files` 可复现本地文件扩展的启用问题。该 wheel 声明入口点名 `local_files`,
而扩展类身份是 `local-files`。Core 在启用时返回 HTTP 409,验收会保留该失败。
`--extension local_files` 可验证本地文件扩展的同一条生命周期。此场景覆盖 Registry 扩展名 `inkcre/local-files`、扩展类身份 `local-files` 和 Python 入口点 `local_files` 之间的映射。

候选均已推送时,也可以在 Registry 分支手动运行 **Registry checks**,把 Python 候选的完整提交 SHA 填入 `core_revision`。
候选均已推送时,可以在 Registry 分支手动运行 **Registry checks**,把 Python 候选的完整提交 SHA 填入 `core_revision`。此路径默认使用 Local Files,覆盖包含连字符的扩展名。

## 从 Registry 工作树联调 Web 的 Module Federation

在 TypeScript 工作树安装锁定依赖和 Chromium 后,从 Registry 工作树运行:

```sh
pdm run registry:verify-browser ../impl-ts ../impl-py
pdm run registry:verify-browser ../impl-ts --core-receipt /path/to/core-receipt.json
```

发布器把当前 TypeScript 工作树构建的 GitHub 扩展发布到临时 Registry。浏览器用 Registry 的真实发行 API、manifest 和模块完成启用,随后用候选 Core 中的数据验收扩展。临时 Registry 只开放 loopback,支持本地 Docker 和 SSH Docker context,退出后清理数据库、对象存储和端口转发。

在 **Registry checks** 同时填入 `core_revision` 和 `browser_revision`,可在 CI 指定确切的三个仓库版本。失败时查看日志和 `registry-browser-acceptance` 附件。

## 独立运行 Registry

```bash
python -m pip install -r requirements-pdm.txt
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ members = ["toolkit", "runtimes/core-py"]

[tool.pdm.scripts]
"check:releases" = "python scripts/release.py check {args}"
"registry:verify-browser" = "python scripts/verify_registry_browser.py {args}"
"registry:verify-peer" = "python scripts/verify_registry_peer.py {args}"
"release:prepare" = "python scripts/release.py prepare {args}"

Expand Down
1 change: 1 addition & 0 deletions runtimes/core-py/.changes/python-package-identity.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
允许 Python 入口点用下划线表示已安装扩展名中的连字符,同时继续校验模块归属和扩展类身份。
14 changes: 8 additions & 6 deletions runtimes/core-py/src/inkcre_extension_runtime_core_py/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,20 @@ async def _start(
) -> RunningExtension:
from .publication import ExtensionRuntimeClaim, ExtensionRuntimeClaimConflictError

runtime_id = model.name.partition("/")[2]
entry_point = acquired.record.python.entry_point
if entry_point.name.replace("_", "-") != runtime_id:
raise ExtensionCompatibilityError(
"Python entry point does not represent the installed Extension identity"
)
modules = DistributionModules(acquired)
try:
claim = ExtensionRuntimeClaim.acquire(acquired.record.python.entry_point.name)
claim = ExtensionRuntimeClaim.acquire(runtime_id)
except ExtensionRuntimeClaimConflictError as error:
raise ExtensionStateConflictError(str(error)) from error
modules = DistributionModules(acquired)
extension_class: type[ExtensionBase] | None = None
try:
extension_class = modules.load(ExtensionBase)
if extension_class.__extid__ != acquired.record.python.entry_point.name:
raise ExtensionCompatibilityError(
"Extension identity differs from installed entry point"
)
extension_class.bind(model)
extension_class.on_start(self.fastapi_app)
modules.assert_origins()
Expand Down
136 changes: 136 additions & 0 deletions scripts/verify_registry_browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
"""Run the Web Host against a disposable candidate Registry serving a real MF Release."""

from __future__ import annotations

import argparse
import json
import os
import signal
import socket
import subprocess
import sys
from contextlib import ExitStack
from pathlib import Path
from tempfile import TemporaryDirectory
from urllib.parse import urlsplit

from verify_registry_peer import (
archive_registry,
grant_publisher,
output,
start_registry,
wait_for,
)


def available_port() -> int:
with socket.socket() as listener:
listener.bind(("127.0.0.1", 0))
return listener.getsockname()[1]


def forward_registry(
stack: ExitStack, docker_endpoint: str, local_port: int, container: str
) -> None:
endpoint = urlsplit(docker_endpoint)
remote_port = int(output("docker", "port", container, "8000/tcp").rsplit(":", 1)[1])
ssh = [
"ssh",
"-NT",
"-o",
"BatchMode=yes",
"-o",
"ExitOnForwardFailure=yes",
"-L",
f"127.0.0.1:{local_port}:127.0.0.1:{remote_port}",
]
if endpoint.port is not None:
ssh.extend(("-p", str(endpoint.port)))
if endpoint.username is not None:
ssh.extend(("-l", endpoint.username))
if not endpoint.hostname or endpoint.hostname.startswith("-"):
raise RuntimeError("Docker SSH context must identify a host")
tunnel = stack.enter_context(subprocess.Popen([*ssh, endpoint.hostname]))
stack.callback(tunnel.terminate)


def verify(web: Path, candidate_arguments: list[str]) -> None:
package = web / "package.json"
if not package.is_file() or "test:e2e:registry" not in json.loads(package.read_text()).get(
"scripts", {}
):
raise RuntimeError(f"Select an impl-ts worktree with test:e2e:registry: {web}")
endpoint = None if os.environ.get("DOCKER_CONTEXT") else os.environ.get("DOCKER_HOST")
endpoint = endpoint or output(
"docker", "context", "inspect", "--format", "{{.Endpoints.docker.Host}}"
)
remote = endpoint.startswith("ssh://")
if not remote and not endpoint.startswith(("unix://", "npipe://")):
raise RuntimeError(
"Browser verification requires a local or SSH Docker context with loopback access"
)
port = available_port()
origin = f"http://127.0.0.1:{port}"
binding = "127.0.0.1::8000" if remote else f"127.0.0.1:{port}:8000"
with TemporaryDirectory(prefix="inkcre-registry-browser-") as directory, ExitStack() as stack:
scratch = Path(directory)
registry_source = scratch / "registry"
revision = archive_registry(registry_source)
container, image, _, _ = start_registry(
scratch,
registry_source,
revision,
stack,
public_origin=origin,
binding=("--publish", binding),
)
if remote:
forward_registry(stack, endpoint, port, container)
live = wait_for(
sys.executable,
"-c",
"from urllib.request import urlopen; import sys; "
"print(urlopen(sys.argv[1], timeout=3).read().decode())",
f"{origin}/livez",
label="Candidate Registry browser origin",
)
if json.loads(live).get("revision") != revision:
raise RuntimeError("Browser origin does not reach the candidate Registry revision")
token = grant_publisher(container, "disposable browser acceptance")
print(
json.dumps({"registry_image": image, "registry_source_revision": revision}), flush=True
)
subprocess.run(
["pnpm", "test:e2e:registry", *candidate_arguments],
env={
**os.environ,
"INKCRE_E2E_REGISTRY_ORIGIN": origin,
"INKCRE_E2E_REGISTRY_TOKEN": token,
},
cwd=web,
check=True,
)


def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("web_worktree", type=Path)
source = parser.add_mutually_exclusive_group(required=True)
source.add_argument("core_worktree", type=Path, nargs="?")
source.add_argument("--core-receipt", type=Path)
args = parser.parse_args()
if args.core_receipt and not args.core_receipt.is_file():
parser.error(f"Core receipt does not exist: {args.core_receipt}")
if args.core_worktree and not (args.core_worktree / "pyproject.toml").is_file():
parser.error(f"Select an impl-py worktree: {args.core_worktree}")
candidate = (
["--core-receipt", str(args.core_receipt.resolve())]
if args.core_receipt
else [str(args.core_worktree.resolve())]
)
verify(args.web_worktree.resolve(), candidate)


if __name__ == "__main__":
signal.signal(signal.SIGTERM, lambda *_: sys.exit(143))
main()
Loading
Loading