From c22e91f642126c5e084f205f8c952821274cdab6 Mon Sep 17 00:00:00 2001 From: Lan_zhijiang Date: Sun, 29 Nov 2026 00:34:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E7=94=A8=20Rust=20=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=B8=85=E5=8D=95=E7=94=9F=E6=88=90=E5=99=A8=E5=B9=B6=E7=B2=BE?= =?UTF-8?q?=E7=AE=80=E9=9D=99=E6=80=81=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/twitter/scripts/accept-archive.py | 28 ++++---------------- scripts/accept_runtime.py | 19 ++----------- scripts/acceptance.py | 24 +++++++++-------- scripts/check.sh | 1 - 4 files changed, 20 insertions(+), 52 deletions(-) diff --git a/extensions/twitter/scripts/accept-archive.py b/extensions/twitter/scripts/accept-archive.py index df6fc6c..86f0a9e 100644 --- a/extensions/twitter/scripts/accept-archive.py +++ b/extensions/twitter/scripts/accept-archive.py @@ -57,6 +57,11 @@ def redirect_request(self, *args): ) j.env["INKCRE_PEER_LEASE_SECONDS"] = "3" j.env["TWITTER_X_MONKEY_JWT_LIFETIME_SECONDS"] = str(session_lifetime_seconds) + binary = options.extension_binary.resolve(strict=True) + wrapper = work / "twitter-wrapper" + wrapper.write_text("#!/bin/sh\nexec " + shlex.quote(str(binary)) + "\n") + wrapper.chmod(0o700) + j.write_plugin_manifest(work / "twitter.json", wrapper, "inkcre/twitter", "0.1.0") db = psycopg.connect(dsn, autocommit=True) snapshot = db.execute( "SELECT config,state FROM inkcre.extensions WHERE name='inkcre/twitter'" @@ -64,29 +69,6 @@ def redirect_request(self, *args): fd = os.open(recovery, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600) with os.fdopen(fd, "w") as output: json.dump({"config": snapshot[0], "state": snapshot[1], "peer": j.peer}, output) - binary = options.extension_binary.resolve(strict=True) - manifest = work / "twitter.json" - wrapper = work / "twitter-wrapper" - wrapper.write_text("#!/bin/sh\nexec " + shlex.quote(str(binary)) + "\n") - wrapper.chmod(0o700) - import hashlib - - manifest.write_text( - json.dumps( - { - "schema_version": 1, - "name": "inkcre/twitter", - "version": "0.1.0", - "distribution": "rust_stdio", - "host_sdk": "core-rs", - "host_sdk_version": "^0.1", - "protocol_version": 1, - "executable": wrapper.name, - "sha256": hashlib.sha256(wrapper.read_bytes()).hexdigest(), - } - ) - ) - j.env["INKCRE_EXTENSION_MANIFESTS"] = str(manifest) def request( method, path, body=None, headers=None, cookie=None, peer=False, expected=200 diff --git a/scripts/accept_runtime.py b/scripts/accept_runtime.py index 7bad589..72a33b9 100644 --- a/scripts/accept_runtime.py +++ b/scripts/accept_runtime.py @@ -2,7 +2,6 @@ """显式运行知识能力、真实 RSS/Atom worker 与插件取消的端到端旅程。""" import argparse -import hashlib from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer import json from pathlib import Path @@ -112,21 +111,6 @@ def __init__(self, args, directory, feed): self.env["INKCRE_NO_CRON"] = "true" self.env["INKCRE_NO_WORKER"] = "true" - def prepare_plugin(self): - directory = self.directory / "plugin" - directory.mkdir() - executable = directory / self.args.extension_binary.name - shutil.copy2(self.args.extension_binary, executable) - manifest = directory / "extension.json" - manifest.write_text(json.dumps({ - "schema_version": 1, "name": "inkcre/rss", "version": "0.1.0", - "distribution": "rust_stdio", "host_sdk": "core-rs", "host_sdk_version": "^0.1", - "protocol_version": 1, "executable": executable.name, - "sha256": hashlib.sha256(executable.read_bytes()).hexdigest(), - })) - self.env["INKCRE_EXTENSION_MANIFESTS"] = str(manifest) - self.plugin = quote("inkcre/rss", safe="") - def items(self, path): return self.request("GET", path + "?limit=1000")["items"] @@ -192,7 +176,8 @@ def run(self): capture_output=True, text=True, timeout=60) if check.returncode or json.loads(check.stdout).get("environment") != "development": raise RuntimeError("runtime journey requires a disposable development database") - self.prepare_plugin() + self.prepare_plugin("inkcre/rss") + self.plugin = quote("inkcre/rss", safe="") self.start() if any(self.items(path) for path in ("/api/v1/blocks", "/api/v1/sources", "/api/v1/jobs", "/api/v1/crons")): raise RuntimeError("runtime journey requires an empty dedicated development info-base") diff --git a/scripts/acceptance.py b/scripts/acceptance.py index 51af0e7..6711a15 100644 --- a/scripts/acceptance.py +++ b/scripts/acceptance.py @@ -125,7 +125,17 @@ def stop(self): self.process.wait(timeout=5) raise RuntimeError("app 未优雅退出") - def prepare_plugin(self): + def write_plugin_manifest(self, manifest, executable, name, version): + with manifest.open("wb") as output: + subprocess.run( + [str(self.args.binary), "extension-manifest", "--name", name, + "--version", version, str(executable)], + cwd=ROOT, stdout=output, check=True, + ) + self.manifest_path = manifest + self.env["INKCRE_EXTENSION_MANIFESTS"] = str(manifest) + + def prepare_plugin(self, name): if not self.args.extension_binary: self.env.pop("INKCRE_EXTENSION_MANIFESTS", None) return @@ -133,18 +143,10 @@ def prepare_plugin(self): plugin_dir.mkdir() executable = plugin_dir / self.args.extension_binary.name shutil.copy2(self.args.extension_binary, executable) - manifest = plugin_dir / "extension.json" - self.manifest_path = manifest - manifest.write_text(json.dumps({ - "schema_version": 1, "name": "example/notes", "version": "0.1.0", - "distribution": "rust_stdio", "host_sdk": "core-rs", "host_sdk_version": "^0.1", - "protocol_version": 1, "executable": executable.name, - "sha256": hashlib.sha256(executable.read_bytes()).hexdigest(), - })) - self.env["INKCRE_EXTENSION_MANIFESTS"] = str(manifest) + self.write_plugin_manifest(plugin_dir / "extension.json", executable, name, "0.1.0") def run(self): - self.prepare_plugin() + self.prepare_plugin("example/notes") self.start() self.request("GET", "/api/v1/blocks", token=False, expected=401) self.observations.append("native 数据库准入与 HTTP 匿名拒绝") diff --git a/scripts/check.sh b/scripts/check.sh index d1943b8..a72f00c 100644 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -3,7 +3,6 @@ set -euo pipefail cd "$(dirname "$0")/.." cargo fmt --all -- --check -cargo check --workspace --all-targets --locked cargo clippy --workspace --all-targets --locked -- -D warnings RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --locked