cc6211fd41
## 背景 这是一个独立的 CI 修复 PR,针对 Backend 与 Native shell 测试失败进行修复,不包含资源画布功能变更。 此前 CI 失败主要集中在: - 后台精选素材契约测试初始化缺少来源素材字段。 - `spacetime-module` host 测试因缺少 SpacetimeDB WASM 宿主 ABI 符号而无法链接。 - Native shell 自主创作模式、runtime action、provider batch 和测试初始化之间存在状态机断言不一致。 - 部分失败测试曾被临时绕过,本 PR 恢复这些测试门禁。 ## 变更内容 ### Backend - 补齐后台精选素材 payload 测试所需的来源素材字段。 - 增加 camelCase 序列化断言,防止 snake_case 字段泄漏。 - 调整 server-rs workspace 测试拆分: - 普通 workspace host 测试继续排除 `spacetime-module`,避免其 `spacetime-types` feature 污染其他领域 crate 的 host 链接。 - 新增独立的 `spacetime-module` 单元测试步骤,不再跳过该模块自身测试。 - 为 host 测试构建提供仅测试期的 SpacetimeDB ABI 链接支持。 - 同步更新 CI workflow 断言、开发流程文档和运维验证文档。 ### Native shell - 恢复被临时跳过的 Native shell 失败测试门禁。 - 修复自主创作模式下的完成条件、runtime action 执行、provider batch 和 finalization 状态流转。 - 修正 Tauri/native 测试初始化、恢复流程及断言,使测试与实际运行时协议保持一致。 - 保持自主创作模式的宽松行为,不通过忽略测试规避失败。 ## 验证 当前提交已完成以下本地验证: - `cargo test --locked -p spacetime-module --no-fail-fast` - 259 个测试 - 258 个通过 - 0 个失败 - 1 个已有的外部 fixture 测试 ignored - `cargo check --locked -p spacetime-module --target wasm32-unknown-unknown` - `cargo build --locked -p spacetime-module --target wasm32-unknown-unknown` - `cargo check --locked -p api-server --all-targets` - `npm run check:server-rs-ddd` - `npm run check:spacetime-schema` - `npm run check:encoding` - `npm run test -- scripts/project-ci-workflow.test.ts` - `cargo fmt --manifest-path server-rs/Cargo.toml --all -- --check` - `git diff --check` 没有新增 `#[ignore]` 来规避失败。 ## 测试边界说明 `spacetime-module` 的 host ABI 链接支持仅用于执行纯单元测试,不是 SpacetimeDB runtime 替身。Reducer、procedure 和真实数据库事务行为仍需要通过真实 SpacetimeDB runtime/integration harness 验证。 本机 Windows 上完整 workspace 测试中的 `wallet_refund_outbox` 测试仍有 11 项因 `os error 5(拒绝访问)`失败,表现为临时文件权限/锁定问题;该问题与本 PR 的 SpacetimeDB 模块测试改动无关,也没有通过忽略这些测试来掩盖。 Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/209 Co-authored-by: suzmii <suzmii@qq.com> Co-committed-by: suzmii <suzmii@qq.com>
240 lines
8.5 KiB
YAML
240 lines
8.5 KiB
YAML
name: Project CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
env:
|
|
CI: 'true'
|
|
CARGO_INCREMENTAL: '0'
|
|
CARGO_HTTP_MULTIPLEXING: 'false'
|
|
CARGO_NET_RETRY: '10'
|
|
CARGO_TERM_COLOR: always
|
|
NPM_CONFIG_AUDIT: 'false'
|
|
NPM_CONFIG_FETCH_RETRIES: '10'
|
|
NPM_CONFIG_FETCH_RETRY_FACTOR: '2'
|
|
NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT: '60000'
|
|
NPM_CONFIG_FETCH_RETRY_MINTIMEOUT: '2000'
|
|
NPM_CONFIG_FUND: 'false'
|
|
NPM_CONFIG_PREFER_OFFLINE: 'true'
|
|
RUSTUP_AUTO_INSTALL: '0'
|
|
RUSTC_WRAPPER: ''
|
|
CARGO_BUILD_RUSTC_WRAPPER: ''
|
|
|
|
jobs:
|
|
repository-checks:
|
|
name: Repository checks
|
|
runs-on: genarrative-ci
|
|
steps:
|
|
- name: Checkout full history from Gitea
|
|
env:
|
|
GENARRATIVE_GITEA_FETCH_DEPTH: '0'
|
|
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
run: genarrative-gitea-checkout
|
|
|
|
- name: Validate preinstalled CI job image and sandbox
|
|
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
|
|
|
- name: Resolve comparison base
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
base_ref="$(node -e '
|
|
const fs = require("node:fs");
|
|
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));
|
|
process.stdout.write(event.pull_request?.base?.sha ?? event.before ?? "");
|
|
')"
|
|
if [[ -n "${base_ref}" && ! "${base_ref}" =~ ^0+$ ]]; then
|
|
git cat-file -e "${base_ref}^{commit}" 2>/dev/null || {
|
|
echo "comparison base commit is unavailable: ${base_ref}" >&2
|
|
exit 1
|
|
}
|
|
else
|
|
base_ref="$(git merge-base HEAD origin/master 2>/dev/null || git rev-parse HEAD)"
|
|
fi
|
|
resolved_base_ref="$(git rev-parse --verify "${base_ref}^{commit}" 2>/dev/null || true)"
|
|
head_ref="$(git rev-parse HEAD)"
|
|
if [[ "${resolved_base_ref}" == "${head_ref}" ]]; then
|
|
resolved_base_ref="$(git rev-parse --verify HEAD^ 2>/dev/null || true)"
|
|
fi
|
|
if [[ -z "${resolved_base_ref}" ]]; then
|
|
echo 'comparison base must resolve to a commit distinct from HEAD.' >&2
|
|
exit 1
|
|
fi
|
|
base_ref="${resolved_base_ref}"
|
|
if [[ "${GITHUB_EVENT_NAME:-}" == 'pull_request' ]] \
|
|
&& ! git merge-base --is-ancestor "${base_ref}" HEAD; then
|
|
echo 'pull request head does not contain the latest base commit; update the branch and rerun CI.' >&2
|
|
exit 1
|
|
fi
|
|
echo "SPACETIME_SCHEMA_BASE_REF=${base_ref}" >> "${GITHUB_ENV}"
|
|
|
|
- name: Install npm dependencies
|
|
run: bash scripts/ci-npm-ci-with-retry.sh
|
|
|
|
- name: Run repository checks
|
|
run: npm run check:repository-ci
|
|
|
|
frontend-tests:
|
|
name: Frontend tests
|
|
runs-on: genarrative-ci
|
|
steps:
|
|
- name: Checkout source from Gitea
|
|
env:
|
|
GENARRATIVE_GITEA_FETCH_DEPTH: '1'
|
|
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
run: genarrative-gitea-checkout
|
|
|
|
- name: Validate preinstalled CI job image and sandbox
|
|
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
|
|
|
- name: Install npm dependencies
|
|
run: bash scripts/ci-npm-ci-with-retry.sh
|
|
|
|
- name: Run frontend and script tests
|
|
run: npm run test
|
|
|
|
- name: Run BgFilter worker smoke harness tests
|
|
run: npm run bgfilter-worker:smoke-test
|
|
|
|
- name: Validate production health patrol behavior
|
|
run: npm run check:production-health-patrol
|
|
|
|
- name: Validate production API release behavior
|
|
run: npm run check:production-api-release
|
|
|
|
- name: Validate production API deploy behavior
|
|
run: npm run check:production-api-deploy
|
|
|
|
backend-tests:
|
|
name: Backend tests
|
|
runs-on: genarrative-ci
|
|
steps:
|
|
- name: Checkout full history from Gitea
|
|
env:
|
|
GENARRATIVE_GITEA_FETCH_DEPTH: '0'
|
|
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
run: genarrative-gitea-checkout
|
|
|
|
- name: Validate preinstalled CI job image and sandbox
|
|
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
|
|
|
- name: Resolve comparison base
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
base_ref="$(node -e '
|
|
const fs = require("node:fs");
|
|
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));
|
|
process.stdout.write(event.pull_request?.base?.sha ?? event.before ?? "");
|
|
')"
|
|
if [[ -n "${base_ref}" && ! "${base_ref}" =~ ^0+$ ]]; then
|
|
git cat-file -e "${base_ref}^{commit}" 2>/dev/null || {
|
|
echo "comparison base commit is unavailable: ${base_ref}" >&2
|
|
exit 1
|
|
}
|
|
else
|
|
base_ref="$(git merge-base HEAD origin/master 2>/dev/null || git rev-parse HEAD)"
|
|
fi
|
|
resolved_base_ref="$(git rev-parse --verify "${base_ref}^{commit}" 2>/dev/null || true)"
|
|
head_ref="$(git rev-parse HEAD)"
|
|
if [[ "${resolved_base_ref}" == "${head_ref}" ]]; then
|
|
resolved_base_ref="$(git rev-parse --verify HEAD^ 2>/dev/null || true)"
|
|
fi
|
|
if [[ -z "${resolved_base_ref}" ]]; then
|
|
echo 'comparison base must resolve to a commit distinct from HEAD.' >&2
|
|
exit 1
|
|
fi
|
|
base_ref="${resolved_base_ref}"
|
|
if [[ "${GITHUB_EVENT_NAME:-}" == 'pull_request' ]] \
|
|
&& ! git merge-base --is-ancestor "${base_ref}" HEAD; then
|
|
echo 'pull request head does not contain the latest base commit; update the branch and rerun CI.' >&2
|
|
exit 1
|
|
fi
|
|
echo "SPACETIME_SCHEMA_BASE_REF=${base_ref}" >> "${GITHUB_ENV}"
|
|
|
|
- name: Install npm dependencies
|
|
run: bash scripts/ci-npm-ci-with-retry.sh
|
|
|
|
- name: Prepare server-rs Rust dependencies
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
for attempt in $(seq 1 5); do
|
|
if cargo fetch --locked \
|
|
--target x86_64-unknown-linux-gnu \
|
|
--manifest-path server-rs/Cargo.toml; then
|
|
break
|
|
fi
|
|
if [[ "${attempt}" -eq 5 ]]; then
|
|
echo 'server-rs Cargo dependency fetch failed after 5 attempts.' >&2
|
|
exit 1
|
|
fi
|
|
sleep $((attempt * 2))
|
|
done
|
|
|
|
- name: Check server-rs boundaries
|
|
run: npm run check:server-rs-ddd
|
|
|
|
- name: Run server-rs workspace tests
|
|
run: cargo test --locked --workspace --exclude spacetime-module --no-fail-fast --manifest-path server-rs/Cargo.toml
|
|
|
|
- name: Run SpacetimeDB module unit tests
|
|
run: cargo test --locked -p spacetime-module --no-fail-fast --manifest-path server-rs/Cargo.toml
|
|
|
|
- name: Check api-server targets
|
|
run: cargo check --locked -p api-server --all-targets --manifest-path server-rs/Cargo.toml
|
|
|
|
- name: Check SpacetimeDB module
|
|
run: cargo check --locked -p spacetime-module --manifest-path server-rs/Cargo.toml
|
|
|
|
native-shell-tests:
|
|
name: Native shell tests
|
|
runs-on: genarrative-ci
|
|
steps:
|
|
- name: Checkout full history from Gitea
|
|
env:
|
|
GENARRATIVE_GITEA_FETCH_DEPTH: '0'
|
|
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
run: genarrative-gitea-checkout
|
|
|
|
- name: Validate preinstalled CI job image and sandbox
|
|
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
|
|
|
- name: Install npm dependencies
|
|
run: bash scripts/ci-npm-ci-with-retry.sh
|
|
|
|
- name: Prepare native Rust dependencies
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
for manifest_path in \
|
|
server-rs/Cargo.toml \
|
|
apps/desktop-shell/src-tauri/Cargo.toml \
|
|
apps/ai-game-creator-shell/src-tauri/Cargo.toml; do
|
|
for attempt in $(seq 1 5); do
|
|
if cargo fetch --locked \
|
|
--target x86_64-unknown-linux-gnu \
|
|
--manifest-path "${manifest_path}"; then
|
|
break
|
|
fi
|
|
if [[ "${attempt}" -eq 5 ]]; then
|
|
echo "Cargo dependency fetch failed after 5 attempts: ${manifest_path}" >&2
|
|
exit 1
|
|
fi
|
|
sleep $((attempt * 2))
|
|
done
|
|
done
|
|
|
|
- name: Run native shell gates
|
|
run: npm run check:native-shells
|
|
|
|
- name: Ensure native lockfiles are unchanged
|
|
run: git diff --exit-code -- apps/desktop-shell/src-tauri/Cargo.lock apps/ai-game-creator-shell/src-tauri/Cargo.lock
|