From dd9482c314fb585fdc464a0b432e8a55e02fbbd9 Mon Sep 17 00:00:00 2001 From: zjncs <18910855655@163.com> Date: Mon, 21 Sep 2026 10:29:20 +0800 Subject: [PATCH] docs(authoring): publish pipeline evidence and RISC-V re-verify script - Record the 2026-09-21 end-to-end publish run: author -> validate -> submit PUBLIC -> async scan (SKILL_SCANNER:SAFE) -> admin review -> PUBLISHED, publicly retrievable, driven by the new scripts/authoring-publish-e2e.sh (16 checks, kept for re-runs). - Document the security configuration keys and baseline, the docker default for local-script execution, and the migration renumber to V66. - Add scripts/riscv64-verify.sh (native vs QEMU auto-detect) plus the native-hardware checklist; native runs remain an open item with no RISC-V hardware available to the project. Signed-off-by: zjncs <18910855655@163.com> --- docs/26-skill-authoring-platform.md | 81 +++++++-- scripts/authoring-publish-e2e.sh | 259 ++++++++++++++++++++++++++++ scripts/riscv64-verify.sh | 194 +++++++++++++++++++++ 3 files changed, 523 insertions(+), 11 deletions(-) create mode 100755 scripts/authoring-publish-e2e.sh create mode 100755 scripts/riscv64-verify.sh diff --git a/docs/26-skill-authoring-platform.md b/docs/26-skill-authoring-platform.md index cb4aa266a..e6592e248 100644 --- a/docs/26-skill-authoring-platform.md +++ b/docs/26-skill-authoring-platform.md @@ -45,7 +45,8 @@ skillhub-storage 草稿文件按内容寻址存入对象存储(与 Skill ## 领域模型与数据表 -迁移 `V60__authoring_platform.sql` 新增六张表: +迁移 `V66__authoring_platform.sql` 新增六张表(初稿编号 V60,因上游 #874 统一身份 +平台占用了 V60–V65,rebase 后顺延为 V66): | 表 | 职责 | | --- | --- | @@ -183,16 +184,21 @@ Skill 版本,扫描与审核沿用平台原有机制,没有旁路。 | `run-timeout-ms` | 900000 | 单次运行硬上限(15 分钟) | | `stale-run-minutes` | 30 | 崩溃恢复清扫阈值 | | `local-script.enabled` | true | 本地脚本运行时开关 | -| `local-script.execution-mode` | inline | 脚本执行后端:`inline`(主机子进程)/ `docker`(锁定容器,`SKILLHUB_AUTHORING_LOCAL_SCRIPT_MODE`) | +| `local-script.execution-mode` | **docker** | 脚本执行后端:`docker`(锁定容器,生产默认)/ `inline`(主机子进程,仅 local/dev/test profile;否则启动即失败,`SKILLHUB_AUTHORING_LOCAL_SCRIPT_MODE`) | | `local-script.docker.image` / `memory` / `cpus` / `pids-limit` / `tmpfs-size` | alpine:3.20 / 256m / 1.0 / 128 / 64m | 容器隔离参数(`SKILLHUB_AUTHORING_DOCKER_*`);镜像需自带 Skill 用到的解释器 | | `openai-compatible.enabled` | false | LLM 运行时开关(默认关闭) | | `openai-compatible.api-key` | 空 | 服务端密钥,绝不写入草稿绑定 | | `openai-compatible.default-endpoint` / `default-model` | 空 | prompt 任务的默认 LLM | | `openai-compatible.max-tool-rounds` | 4 | 单个 prompt 任务的最大对话轮数(含 MCP 工具执行) | +| `openai-compatible.allow-private-endpoints` | false | LLM endpoint 的 SSRF 放行开关:私网 LLM(如内部 vLLM)才设 true(`SKILLHUB_AUTHORING_LLM_ALLOW_PRIVATE`) | +| `mcp.allow-private-endpoints` | false | http/sse MCP endpoint 的 SSRF 放行开关(`SKILLHUB_AUTHORING_MCP_ALLOW_PRIVATE`);链路本地/云元数据地址任何情况下都拒绝 | +| `mcp.stdio-enabled` | false | stdio MCP 传输总开关(`SKILLHUB_AUTHORING_MCP_STDIO_ENABLED`)——服务器侧进程执行,生产默认关闭 | +| `mcp.env-allowlist` | 空 | 允许 `envRefs` 引用的服务器环境变量名单(逗号分隔,`SKILLHUB_AUTHORING_MCP_ENV_ALLOWLIST`);默认空 = 全部拒绝 | +| `mcp.docker.image` / `memory` / `cpus` / `pids-limit` / `tmpfs-size` | alpine:3.20 / 256m / 1.0 / 128 / 64m | docker 模式下 stdio MCP 服务器的容器隔离参数(`SKILLHUB_AUTHORING_MCP_DOCKER_*`) | ### 部署要点 -- **数据库**:Flyway 迁移 V60 自动建表,无手工步骤;JSONB 列要求 PostgreSQL +- **数据库**:Flyway 迁移 V66 自动建表,无手工步骤;JSONB 列要求 PostgreSQL (平台既有要求,无新增)。 - **启用 prompt 任务**:配置 `SKILLHUB_AUTHORING_LLM_ENABLED=true` 并给出 endpoint/model/api-key;不启用时含 prompt 任务的草稿会得到 `RUNTIME_DISABLED` @@ -200,9 +206,12 @@ Skill 版本,扫描与审核沿用平台原有机制,没有旁路。 - **启用容器隔离**:`SKILLHUB_AUTHORING_LOCAL_SCRIPT_MODE=docker` 并确保运行节点 可访问 Docker daemon。镜像需包含 Skill 用到的解释器(alpine 只带 `sh`; python3/node 的 Skill 应换基础镜像)。脚本执行不再依赖主机环境。 -- **MCP 服务器**:stdio 传输的 MCP 命令在服务器进程侧 spawn,`envRefs` 点名的 - 环境变量从服务器环境注入(这是凭据到达 MCP 服务器的唯一通道);http/sse - 传输直接访问声明的 endpoint。验证时每台声明的服务器都会被真实探测。 +- **MCP 服务器**:stdio 传输默认整体关闭(`mcp.stdio-enabled`),开启后命令在 + docker 执行模式下运行于与脚本相同的锁定容器(无网络、资源上限、只读根文件 + 系统,关闭时强制 `docker rm -f` 清理);inline 模式仅限 local/dev/test + profile。`envRefs` 只能引用 `mcp.env-allowlist` 点名的环境变量(默认空 = + 全部拒绝),这是凭据到达 MCP 服务器的唯一通道。http/sse 传输访问的 + endpoint 必须通过 SSRF 策略(见下)。验证时每台声明的服务器都会被真实探测。 - **工作区**:验证运行会在 `workspace-root` 下创建一次性目录并在结束后清理, 生产环境建议独立磁盘分区并纳入监控;多实例部署时运行在工作区所在节点本地 执行,无需共享存储。 @@ -210,8 +219,21 @@ Skill 版本,扫描与审核沿用平台原有机制,没有旁路。 `linux/riscv64` 构建路径(见 `docs/RISCV64.md`)。local-script 运行时只依赖 容器内 POSIX 工具(`sh`、`wc` 等),Temurin 运行时镜像自带;安全扫描器的 RISC-V 限制与创作平台无关(扫描发生在提交后的发布管线)。 -- **安全基线**:脚本在清空环境的最小工作区执行、解释器白名单、路径不得越界、 - 绑定禁止内嵌凭据、单文件 10MB / 包 100MB / 500 文件上限与发布侧一致。 +- **安全基线**: + - **SSRF 防护**:MCP http/sse endpoint 与 OpenAI 兼容 endpoint 在保存时、 + 连接时双重校验——只允许 http(s),主机必须可解析,且解析到的地址不得为 + 链路本地(含云元数据 169.254.169.254)、组播或未指定地址(无条件拒绝), + 也不得为环回/RFC1918/ULA/CGNAT(除非对应表面的 `allow-private-endpoints` + 放行)。HTTP 客户端从不跟随重定向(30x 直接报错),单响应体上限 2MiB, + stdio 单行上限 2MiB——阻断"公网 URL 302 跳元数据"与超大响应/超长行的 + 内存耗尽攻击。已知边界:策略在检查时解析域名,HttpClient 连接时再次解析, + 可缓解但无法完全消除 DNS rebinding 竞态(绑定已校验地址的 socket 会破坏 + 虚拟主机 endpoint,未实现)。 + - **生产强制容器**:`execution-mode` 默认 `docker`;若在非 local/dev/test + profile 下配置了 inline,应用启动即失败(`AuthoringStartupGuard`)。 + - **其余既有边界**:脚本在清空环境的最小工作区执行、解释器白名单、路径 + 不得越界、绑定禁止内嵌凭据、单文件 10MB / 包 100MB / 500 文件上限与 + 发布侧一致。 ### RISC-V64 验证记录(2026-09-20) @@ -222,7 +244,7 @@ Skill 版本,扫描与审核沿用平台原有机制,没有旁路。 `eclipse-temurin:21-jre-noble` 的 riscv64 官方变体),`docker image inspect` 确认 `linux/riscv64`。 - **启动**:QEMU 模拟下 Spring Boot 91.9 秒完成启动,`/actuator/health` 返回 - 200;Flyway 在全新 PostgreSQL 16 上完成全部迁移(含 V60 创作平台表)。 + 200;Flyway 在全新 PostgreSQL 16 上完成全部迁移(含 V66 创作平台表)。 - **创作平台全流程(REST API)**:创建草稿 → 读取脚手架 SKILL.md → 保存 `scripts/check.sh` 与 `validation.yaml` → 保存 local-script 绑定 → 启动验证 → 运行 `SUCCEEDED`(0 错误 0 警告),12 条事件完整落库且脚本 stdout 出现在事件 @@ -235,14 +257,51 @@ Skill 版本,扫描与审核沿用平台原有机制,没有旁路。 RISC-V 硬件上的全栈冒烟(PostgreSQL/Redis/对象存储/scanner)仍按 `docs/RISCV64.md` 的边界声明执行。 +#### 复验脚本与原生硬件清单 + +上述流程已固化为 `scripts/riscv64-verify.sh`(自动识别宿主架构:riscv64 主机 +原生执行,其余走 QEMU;对独立数据库跑 创建→验证→SUCCEEDED→事件流检查)。 +在真实 RISC-V64 硬件或 CI runner 上完成原生验证时,除直接运行该脚本外, +按以下清单执行并留档: + +1. `uname -m` 输出 `riscv64`(非 QEMU:`/proc/cpuinfo` 无 "emodel"/QEMU 标记, + 且启动日志无 qemu 前缀); +2. PostgreSQL 16、Redis 7 以 riscv64 原生镜像运行(非 binfmt 转译); +3. `scripts/riscv64-verify.sh` 全部检查通过,记录 耗时 与 事件数 两个数字; +4. `execution-mode: docker` 下再跑一次(验证 alpine:3.20 riscv64 变体内的 + 脚本隔离执行); +5. 浏览器 E2E(`e2e/authoring-flow.spec.ts`)对准该实例跑通。 + +截至 2026-09-20,本项目尚无原生 RISC-V 硬件资源,上述第 1–5 项为待完成项, +已有证据为 QEMU 模拟级(见上)。 + +### 发布管线端到端证据(2026-09-21) + +`scripts/authoring-publish-e2e.sh` 在本地 dev 栈(PostgreSQL/Redis/MinIO + +skill-scanner :8000,`local` profile)上实跑全链路并留档,16/16 检查通过: + +- **创作与验证**(普通用户 `local-user`):草稿 94 → SKILL.md/`scripts/check.sh`/ + `validation.yaml` → local-script 绑定 → 验证运行 `SUCCEEDED`; +- **提交 PUBLIC**:submit 返回 skill 33 / version 33 / slug + `publish-evidence-1789957612` / 版本号 `20260921.102653`,版本进入 + `SCANNING`(非 SUPER_ADMIN 提交不会自动发布); +- **安全扫描**:异步完成后版本回到 `PENDING_REVIEW`,`security_audit` 落库 + `SKILL_SCANNER:SAFE:1`(1 条发现、判定安全); +- **人工审核**:平台管理员(`local-admin`,SUPER_ADMIN)通过 + `POST /api/web/reviews/1/approve` 批准,审核任务 `APPROVED`; +- **发布终态**:`skill_version.status = PUBLISHED`、`published_at` 已置位、 + `skill.visibility = PUBLIC`,另一普通用户(`local-plain-user`)可公开检索 + 该 Skill,且草稿回填 `submittedSkillId = 33`。 + ## 测试 | 层 | 位置 | 覆盖 | | --- | --- | --- | | 领域单测 | `skillhub-domain/…/authoring/` | `DraftStructureValidatorTest`(结构规则与修复建议)、`ValidationSpecParserTest`(防御式 YAML 解析、任务/断言语义)、`AssertionEvaluatorTest`(全部断言类型与失败信息)、`SkillScaffoldGeneratorTest` | | 运行时单测 | `skillhub-app/…/authoring/adapter/` | `DockerScriptCommandBuilderTest`(隔离参数与挂载构造)、`DockerScriptRuntimeAdapterTest`(真实容器内实证:无网络路由、只读根文件系统、工作区可写、输出捕获;无 Docker 时静默跳过)、`OpenAiCompatibleRuntimeAdapterToolLoopTest`(agent 循环:MCP 工具发现→模型调用→真实执行→轨迹回填,toolFilters/toolAllowlist 过滤、轮数上限) | -| MCP 单测 | `skillhub-app/…/authoring/mcp/` | `HttpMcpClientTest`(initialize/tools 握手、会话头复用、SSE 帧解析、错误结果、不可达报错,对真实本地 HTTP 服务器)、`StdioMcpClientTest`(stdio 传输对 python3 子进程)、`McpProbeServiceTest`(连不上→`MCP_CONNECT_FAILED`、未知 toolFilter→告警、可跳过畸形声明) | -| 端到端集成 | `skillhub-app/…/authoring/AuthoringFlowIntegrationTest` | Testcontainers 真实 PostgreSQL 上跑通完整闭环:建草稿 → 改文件 → 绑定运行时 → 三层验证 → 修复发现 → 复验 → 提交(`ddl-auto=validate` 顺带校验 V60 与实体映射一致) | +| MCP 单测 | `skillhub-app/…/authoring/mcp/` | `HttpMcpClientTest`(initialize/tools 握手、会话头复用、SSE 帧解析、错误结果、不可达报错、**30x 重定向不跟随、2MiB 响应上限**,对真实本地 HTTP 服务器)、`StdioMcpClientTest`(stdio 传输对 python3 子进程;**2MiB 单行上限 + 进程销毁、关闭时清理命令执行**)、`McpProbeServiceTest`(连不上→`MCP_CONNECT_FAILED`、未知 toolFilter→告警、可跳过畸形声明)、`McpClientFactoryTest`(**连接时安全策略:被拒 endpoint/被禁 stdio 不建连不建进程、envRefs 白名单过滤、docker 包装参数**) | +| 安全策略单测 | `skillhub-app/…/config/` | `ConfiguredAuthoringSecurityPolicyTest`(SSRF 地址分类:云元数据/链路本地无条件拒绝、环回/RFC1918/ULA/CGNAT 按表面开关、公网放行)、`AuthoringStartupGuardTest`(非 local/dev/test profile + inline → 启动失败) | +| 端到端集成 | `skillhub-app/…/authoring/AuthoringFlowIntegrationTest` | Testcontainers 真实 PostgreSQL 上跑通完整闭环:建草稿 → 改文件 → 绑定运行时 → 三层验证 → 修复发现 → 复验 → 提交(`ddl-auto=validate` 顺带校验 V66 与实体映射一致) | | 前端单测 | `web/src/features/authoring/*.test.*` | 事件按 seq 合并去重、SSE 生命周期(回放合并、终态关闭、断线轮询降级)、修复 diff 预览、二进制文件 base64 处理 | | 浏览器 E2E | `web/e2e/authoring-flow.spec.ts` | Playwright 真实 API 全 UI 闭环:创建草稿(命名空间/名称对话框)→ 文件编辑(SKILL.md/脚本/validation.yaml)→ 保存运行时绑定 → 启动验证至 Succeeded(事件控制台含脚本输出)→ 提交对话框过闸;坏 frontmatter → 失败发现 → diff 预览 → 两步确认应用修复 → 一键复验通过;二进制资源上传 → 只读面板(大小/类型/sha256)与字节级校验。断言落在持久 UI 状态(按钮态、徽章、响应体)而非易失 toast | | 活体冒烟 | `scripts/authoring-smoke-test.sh` | 对运行中的服务器 35 项检查、四个场景:全层验证并提交;坏 frontmatter → 定位 → 应用修复 → 复验;守卫(未验证不可提交、跨用户不可读他人草稿);MCP 探测(死端点报 `MCP_CONNECT_FAILED`、本地假 MCP 服务器工具被发现并写入事件流、未知 toolFilter 仅告警),幂等可重复执行 | diff --git a/scripts/authoring-publish-e2e.sh b/scripts/authoring-publish-e2e.sh new file mode 100755 index 000000000..7fc287623 --- /dev/null +++ b/scripts/authoring-publish-e2e.sh @@ -0,0 +1,259 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Publish-pipeline end-to-end evidence run for the authoring platform. +# +# Extends scripts/authoring-smoke-test.sh past the submit step: a validated +# draft is submitted as PUBLIC by a regular user, the security scanner +# (skillhub-skill-scanner-1) scans it asynchronously, a platform admin +# approves the review task, and the version reaches the PUBLISHED terminal +# state with the skill publicly retrievable. +# +# Each check prints PASS/FAIL plus the observed identifiers so the output can +# be pasted directly as evidence. Requires the local dev profile (mock auth, +# Postgres/Redis/scanner/minio from the compose stack). Usage: +# scripts/authoring-publish-e2e.sh [base-url] + +BASE_URL="${1:-http://localhost:8080}" +PASS=0 +FAIL=0 +COOKIE="$(mktemp)" +ADMIN_COOKIE="$(mktemp)" +RUN_ID="$(date +%s)" +NAME="publish-evidence-$RUN_ID" +PSQL=(docker exec skillhub-postgres-1 psql -U skillhub -d skillhub -tAc) + +cleanup() { + rm -f "$COOKIE" "$ADMIN_COOKIE" +} +trap cleanup EXIT + +pass() { + echo "PASS: $1" + PASS=$((PASS + 1)) +} + +fail() { + echo "FAIL: $1" + FAIL=$((FAIL + 1)) +} + +json_field() { + local json="$1" + local expr="$2" + JSON_INPUT="$json" python3 - "$expr" <<'PY' +import json +import os +import sys + +expr = sys.argv[1] +data = json.loads(os.environ["JSON_INPUT"]) +value = data +for part in expr.split('.'): + if part.isdigit(): + value = value[int(part)] + else: + value = value[part] +if isinstance(value, (dict, list)): + print(json.dumps(value, ensure_ascii=False)) +else: + print(value) +PY +} + +assert_equals() { + local description="$1" + local expected="$2" + local actual="$3" + if [[ "$expected" == "$actual" ]]; then + pass "$description" + else + fail "$description (expected '$expected', got '$actual')" + fi +} + +api() { + local method="$1" + local path="$2" + local data="${3:-}" + if [[ -n "$data" ]]; then + curl -sS -H "X-Mock-User-Id: local-user" -b "$COOKIE" -c "$COOKIE" \ + -H "X-XSRF-TOKEN: $CSRF" -H "Content-Type: application/json" \ + -X "$method" "$BASE_URL$path" -d "$data" + else + curl -sS -H "X-Mock-User-Id: local-user" -b "$COOKIE" -c "$COOKIE" \ + -H "X-XSRF-TOKEN: $CSRF" -X "$method" "$BASE_URL$path" + fi +} + +admin_api() { + local method="$1" + local path="$2" + local data="${3:-}" + if [[ -n "$data" ]]; then + curl -sS -H "X-Mock-User-Id: local-admin" -b "$ADMIN_COOKIE" -c "$ADMIN_COOKIE" \ + -H "X-XSRF-TOKEN: $ADMIN_CSRF" -H "Content-Type: application/json" \ + -X "$method" "$BASE_URL$path" -d "$data" + else + curl -sS -H "X-Mock-User-Id: local-admin" -b "$ADMIN_COOKIE" -c "$ADMIN_COOKIE" \ + -H "X-XSRF-TOKEN: $ADMIN_CSRF" -X "$method" "$BASE_URL$path" + fi +} + +await_run_terminal() { + local run_id="$1" + local status="" + for _ in $(seq 1 60); do + status="$(json_field "$(api GET "/api/web/authoring/runs/$run_id")" "data.status")" + case "$status" in + SUCCEEDED|FAILED|CANCELLED|TIMED_OUT) break ;; + esac + sleep 1 + done + echo "$status" +} + +await_db_value() { + local query="$1" + local expected="$2" + local timeout="${3:-60}" + local value="" + for _ in $(seq 1 "$timeout"); do + value="$("${PSQL[@]}" "$query" 2>/dev/null || true)" + [[ "$value" == "$expected" ]] && break + sleep 1 + done + echo "$value" +} + +echo "=== Authoring → Publish Pipeline E2E Evidence ===" +echo "Target: $BASE_URL Run: $RUN_ID" +echo + +curl -s -c "$COOKIE" -H "X-Mock-User-Id: local-user" "$BASE_URL/api/v1/auth/providers" >/dev/null +CSRF="$(awk '$6 == "XSRF-TOKEN" { print $7 }' "$COOKIE" | tail -n 1)" +curl -s -c "$ADMIN_COOKIE" -H "X-Mock-User-Id: local-admin" "$BASE_URL/api/v1/auth/providers" >/dev/null +ADMIN_CSRF="$(awk '$6 == "XSRF-TOKEN" { print $7 }' "$ADMIN_COOKIE" | tail -n 1)" + +# ---------------------------------------------------------------- author → validate + +echo "--- Stage 1: author and validate (regular user local-user) ---" + +DRAFT_RESPONSE="$(api POST /api/web/authoring/drafts "{\"namespaceSlug\":\"global\",\"name\":\"$NAME\"}")" +assert_equals "Draft created" "0" "$(json_field "$DRAFT_RESPONSE" "code")" +DRAFT_ID="$(json_field "$DRAFT_RESPONSE" "data.id")" +echo " draft id: $DRAFT_ID" + +SKILL_MD="--- +name: $NAME +description: publish pipeline evidence skill for run $RUN_ID +--- + +# Publish pipeline evidence + +Runs a shell check that must succeed before submission. +" +api PUT "/api/web/authoring/drafts/$DRAFT_ID/files" \ + "{\"path\":\"SKILL.md\",\"content\":$(python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))' <<< "$SKILL_MD"),\"contentType\":\"text/markdown\"}" >/dev/null +api PUT "/api/web/authoring/drafts/$DRAFT_ID/files" \ + "{\"path\":\"scripts/check.sh\",\"content\":\"#!/bin/sh\necho publish-evidence-ok\n\",\"contentType\":\"text/x-shellscript\"}" >/dev/null +api PUT "/api/web/authoring/drafts/$DRAFT_ID/files" \ + "{\"path\":\"validation.yaml\",\"content\":\"version: 1\\ntasks:\\n - name: check\\n description: script prints the evidence marker\\n type: script\\n script: scripts/check.sh\\n args: []\\n timeoutMs: 10000\\n assertions:\\n - type: exit_code\\n equals: 0\\n - type: stdout_contains\\n value: publish-evidence-ok\\n\",\"contentType\":\"application/yaml\"}" >/dev/null + +BINDING_RESPONSE="$(api PUT "/api/web/authoring/drafts/$DRAFT_ID/runtime" \ + '{"agentType":"local-script","config":{"interpreter":"sh"},"toolAllowlist":[]}')" +assert_equals "local-script binding saved" "0" "$(json_field "$BINDING_RESPONSE" "code")" + +RUN_RESPONSE="$(api POST "/api/web/authoring/drafts/$DRAFT_ID/runs")" +RUN_ID_LOCAL="$(json_field "$RUN_RESPONSE" "data.id")" +assert_equals "Validation run SUCCEEDED" "SUCCEEDED" "$(await_run_terminal "$RUN_ID_LOCAL")" + +# ---------------------------------------------------------------- submit PUBLIC + +echo +echo "--- Stage 2: submit as PUBLIC (enters publish pipeline) ---" + +SUBMIT_RESPONSE="$(api POST "/api/web/authoring/drafts/$DRAFT_ID/submit" '{"visibility":"PUBLIC"}')" +assert_equals "Draft submitted as PUBLIC" "0" "$(json_field "$SUBMIT_RESPONSE" "code")" +SKILL_ID="$(json_field "$SUBMIT_RESPONSE" "data.skillId")" +VERSION_ID="$(json_field "$SUBMIT_RESPONSE" "data.versionId")" +SKILL_VERSION="$(json_field "$SUBMIT_RESPONSE" "data.version")" +SLUG="$(json_field "$SUBMIT_RESPONSE" "data.slug")" +echo " skill id: $SKILL_ID version id: $VERSION_ID slug: $SLUG version: $SKILL_VERSION" + +DB_STATUS="$("${PSQL[@]}" "SELECT status FROM skill_version WHERE id = $VERSION_ID")" +if [[ "$DB_STATUS" == "PENDING_REVIEW" || "$DB_STATUS" == "SCANNING" ]]; then + pass "Version entered pipeline in $DB_STATUS (not auto-published)" +else + fail "Version should be PENDING_REVIEW/SCANNING, got '$DB_STATUS'" +fi + +# ---------------------------------------------------------------- security scan + +echo +echo "--- Stage 3: asynchronous security scan (scanner on :8000) ---" + +SCAN_STATUS="$(await_db_value \ + "SELECT status FROM skill_version WHERE id = $VERSION_ID" "PENDING_REVIEW" 90)" +assert_equals "Scan completed, version back to PENDING_REVIEW" "PENDING_REVIEW" "$SCAN_STATUS" + +SCAN_ROW="$("${PSQL[@]}" "SELECT scanner_type || ':' || verdict || ':' || findings_count FROM security_audit WHERE skill_version_id = $VERSION_ID AND deleted_at IS NULL ORDER BY id DESC LIMIT 1")" +if [[ -n "$SCAN_ROW" && "$SCAN_ROW" != "" ]]; then + pass "security_audit row recorded: $SCAN_ROW" +else + fail "No security_audit row for version $VERSION_ID" +fi + +REVIEW_TASK_ID="$("${PSQL[@]}" "SELECT id FROM review_task WHERE skill_version_id = $VERSION_ID ORDER BY id DESC LIMIT 1")" +if [[ -n "$REVIEW_TASK_ID" ]]; then + pass "Review task $REVIEW_TASK_ID pending approval" +else + fail "No review task created for version $VERSION_ID" +fi + +# ---------------------------------------------------------------- admin approve + +echo +echo "--- Stage 4: platform admin approves (local-admin) ---" + +APPROVE_RESPONSE="$(admin_api POST "/api/web/reviews/$REVIEW_TASK_ID/approve" \ + '{"comment":"publish-pipeline evidence run"}')" +assert_equals "Review approved" "0" "$(json_field "$APPROVE_RESPONSE" "code")" +REVIEW_STATUS="$(json_field "$APPROVE_RESPONSE" "data.status")" +assert_equals "Review task status APPROVED" "APPROVED" "$REVIEW_STATUS" + +# ---------------------------------------------------------------- terminal state + +echo +echo "--- Stage 5: PUBLISHED terminal state ---" + +DB_STATUS="$("${PSQL[@]}" "SELECT status FROM skill_version WHERE id = $VERSION_ID")" +assert_equals "skill_version.status = PUBLISHED (DB)" "PUBLISHED" "$DB_STATUS" + +PUBLISHED_AT="$("${PSQL[@]}" "SELECT published_at FROM skill_version WHERE id = $VERSION_ID")" +if [[ -n "$PUBLISHED_AT" && "$PUBLISHED_AT" != "" ]]; then + pass "published_at set: $PUBLISHED_AT" +else + fail "published_at not set" +fi + +VISIBILITY="$("${PSQL[@]}" "SELECT visibility FROM skill WHERE id = $SKILL_ID")" +assert_equals "skill.visibility = PUBLIC (DB)" "PUBLIC" "$VISIBILITY" + +DETAIL="$(curl -sS -H "X-Mock-User-Id: local-plain-user" "$BASE_URL/api/web/skills/global/$SLUG")" +assert_equals "Skill publicly retrievable by another user" "0" "$(json_field "$DETAIL" "code")" +assert_equals "Public detail shows visibility PUBLIC" "PUBLIC" "$(json_field "$DETAIL" "data.visibility")" + +SUBMITTED="$(api GET "/api/web/authoring/drafts/$DRAFT_ID")" +assert_equals "Draft shows submitted skill id $SKILL_ID" "$SKILL_ID" "$(json_field "$SUBMITTED" "data.submittedSkillId")" + +# ---------------------------------------------------------------- summary + +echo +if [[ "$FAIL" -eq 0 ]]; then + echo "=== All $PASS checks passed — full chain: create → validate → submit → scan → review → publish ===" + exit 0 +fi +echo "=== $FAIL check(s) failed, $PASS passed ===" +exit 1 diff --git a/scripts/riscv64-verify.sh b/scripts/riscv64-verify.sh new file mode 100755 index 000000000..dd55a5fdb --- /dev/null +++ b/scripts/riscv64-verify.sh @@ -0,0 +1,194 @@ +#!/usr/bin/env bash + +# RISC-V64 live verification of the authoring platform. +# +# Boots the linux/riscv64 server image (native on riscv64 hosts, QEMU-emulated +# elsewhere) against a dedicated PostgreSQL database and drives the full +# authoring flow over the REST API: +# create draft → read scaffold → save script + validation.yaml → bind runtime +# → validate → SUCCEEDED → script stdout visible in the event stream. +# +# The script assumes: +# - the image exists (see "Building the image" below); +# - PostgreSQL and Redis are reachable from the container (defaults use +# host.docker.internal on ports 5432/6379); +# - the DB given by SKILLHUB_RISCV_DB is EMPTY — Flyway migrates it from zero +# (the script never touches your main dev database). +# +# Usage: +# scripts/riscv64-verify.sh [image] # default skillhub-server:riscv64 +# SKILLHUB_RISCV_DB=mydb scripts/riscv64-verify.sh myimage:tag +# +# Building the image (on any host; buildx + QEMU required on non-riscv64): +# cd server && docker buildx build --platform linux/riscv64 \ +# -t skillhub-server:riscv64 --load . +# +# Native hardware note: on a real riscv64 host (uname -m == riscv64) the same +# script runs without emulation; the log line marks which mode you are in. +# QEMU mode proves architecture independence of the JVM workload, native mode +# additionally proves the platform services' riscv64 images. + +set -u + +IMAGE="${1:-skillhub-server:riscv64}" +DB_NAME="${SKILLHUB_RISCV_DB:-skillhub_riscv_check}" +HOST="${SKILLHUB_RISCV_DB_HOST:-host.docker.internal}" +CONTAINER="skillhub-riscv-check" +BASE_URL="http://localhost:18082" +COOKIE="$(mktemp)" +PASS=0 +FAIL=0 + +pass() { echo "PASS: $1"; PASS=$((PASS + 1)); } +fail() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); } + +json_field() { + JSON_INPUT="$1" python3 - "$2" <<'PY' +import json, os, sys +expr = sys.argv[1] +value = json.loads(os.environ["JSON_INPUT"]) +for part in expr.split('.'): + value = value[int(part)] if part.isdigit() else value[part] +print(json.dumps(value, ensure_ascii=False) if isinstance(value, (dict, list)) else value) +PY +} + +csrf_token() { awk '$6 == "XSRF-TOKEN" { print $7 }' "$COOKIE" | tail -n 1; } +bootstrap_csrf() { + curl -s -c "$COOKIE" -H "X-Mock-User-Id: local-user" "$BASE_URL/api/v1/auth/providers" >/dev/null +} +api() { + local method="$1" + local path="$2" + local body="${3:-}" + if [[ -n "$body" ]]; then + curl -s -b "$COOKIE" -c "$COOKIE" -X "$method" -H "Content-Type: application/json" \ + -H "X-Mock-User-Id: local-user" -H "X-XSRF-TOKEN: $(csrf_token)" -d "$body" "$BASE_URL$path" + else + curl -s -b "$COOKIE" -c "$COOKIE" -X "$method" \ + -H "X-Mock-User-Id: local-user" -H "X-XSRF-TOKEN: $(csrf_token)" "$BASE_URL$path" + fi +} + +cleanup() { + docker rm -f "$CONTAINER" >/dev/null 2>&1 || true + rm -f "$COOKIE" +} +trap cleanup EXIT + +echo "=== RISC-V64 authoring platform verification ===" +echo "image: $IMAGE" +echo "database: $DB_NAME on $HOST" +ARCH="$(uname -m)" +if [[ "$ARCH" == "riscv64" ]]; then + echo "mode: NATIVE riscv64 host" +else + echo "mode: QEMU emulation (host arch $ARCH)" +fi +echo + +echo "--- 1. boot the linux/riscv64 image ---" +docker rm -f "$CONTAINER" >/dev/null 2>&1 || true +docker run -d --name "$CONTAINER" -p 18082:8080 "$IMAGE" \ + --spring.profiles.active=local \ + --spring.datasource.url="jdbc:postgresql://$HOST:5432/$DB_NAME" \ + --spring.data.redis.host="$HOST" >/dev/null || { echo "docker run failed"; exit 1; } + +IMAGE_ARCH="$(docker inspect "$CONTAINER" --format '{{.Image}}' >/dev/null 2>&1 && docker exec "$CONTAINER" uname -m 2>/dev/null || echo unknown)" +echo "arch inside container: $IMAGE_ARCH" +if [[ "$IMAGE_ARCH" == "riscv64" ]]; then + pass "container userland is riscv64" +else + fail "container userland is '$IMAGE_ARCH', expected riscv64" +fi + +HEALTHY=0 +for i in $(seq 1 90); do + code=$(curl -s -o /dev/null -w '%{http_code}' "$BASE_URL/actuator/health" 2>/dev/null || true) + if [[ "$code" == "200" ]]; then + echo "health 200 after ~$((i * 10))s" + HEALTHY=1 + break + fi + if ! docker ps --format '{{.Names}}' | grep -q "^$CONTAINER$"; then + echo "CONTAINER DIED — last logs:" + docker logs "$CONTAINER" 2>&1 | tail -30 + exit 1 + fi + sleep 10 +done +if [[ "$HEALTHY" == "1" ]]; then + pass "server boots and becomes healthy" +else + fail "server did not become healthy in 900s" + docker logs "$CONTAINER" 2>&1 | tail -30 + exit 1 +fi + +echo "--- 2. authoring flow over the API ---" +bootstrap_csrf +RUN_TAG="$(date +%s)" +DRAFT="$(api POST /api/web/authoring/drafts \ + "{\"namespaceSlug\":\"global\",\"name\":\"riscv-verify-$RUN_TAG\",\"description\":\"verifies the authoring platform on riscv64\"}")" +if [[ "$(json_field "$DRAFT" "code")" == "0" ]]; then + pass "draft created" +else + fail "draft create: $DRAFT" + exit 1 +fi +DRAFT_ID="$(json_field "$DRAFT" "data.id")" + +SCAFFOLD="$(api GET "/api/web/authoring/drafts/$DRAFT_ID/files/content?path=SKILL.md")" +if echo "$SCAFFOLD" | grep -q "name: riscv-verify-$RUN_TAG"; then + pass "scaffold SKILL.md persisted and readable" +else + fail "scaffold read: $SCAFFOLD" +fi + +api PUT "/api/web/authoring/drafts/$DRAFT_ID/files" \ + '{"path":"scripts/check.sh","content":"#!/bin/sh\necho riscv-script-OK\n","contentType":"text/x-shellscript"}' >/dev/null +api PUT "/api/web/authoring/drafts/$DRAFT_ID/files" \ + '{"path":"validation.yaml","content":"version: 1\ntasks:\n - name: smoke\n description: script runs on riscv64\n type: script\n script: scripts/check.sh\n args: []\n timeoutMs: 60000\n assertions:\n - type: exit_code\n equals: 0\n - type: stdout_contains\n value: riscv-script-OK\n"}' >/dev/null + +BINDING="$(api PUT "/api/web/authoring/drafts/$DRAFT_ID/runtime" \ + '{"agentType":"local-script","config":{"interpreter":"sh"},"toolAllowlist":[],"mcpServers":[]}')" +if [[ "$(json_field "$BINDING" "code")" == "0" ]]; then + pass "runtime binding saved" +else + fail "binding: $BINDING" +fi + +RUN="$(api POST "/api/web/authoring/drafts/$DRAFT_ID/runs" '{}')" +RUN_ID="$(json_field "$RUN" "data.id")" + +STATUS="" +for _ in $(seq 1 60); do + STATUS="$(json_field "$(api GET "/api/web/authoring/runs/$RUN_ID")" "data.status")" + case "$STATUS" in + SUCCEEDED|FAILED|CANCELLED|TIMED_OUT) break ;; + esac + sleep 5 +done +if [[ "$STATUS" == "SUCCEEDED" ]]; then + pass "validation run SUCCEEDED (script executed in the container's riscv64 userland)" +else + fail "validation run ended as $STATUS" +fi + +EVENTS="$(api GET "/api/web/authoring/runs/$RUN_ID/events")" +EVENT_COUNT="$(JSON_INPUT="$EVENTS" python3 -c ' +import json, os +print(len(json.loads(os.environ["JSON_INPUT"])["data"]))' 2>/dev/null || echo 0)" +if echo "$EVENTS" | grep -q "riscv-script-OK"; then + pass "script stdout present in the event stream ($EVENT_COUNT events)" +else + fail "script stdout missing from the event stream" +fi + +echo +if [[ "$FAIL" -eq 0 ]]; then + echo "=== All $PASS checks passed ===" + exit 0 +fi +echo "=== $FAIL check(s) failed, $PASS passed ===" +exit 1