Skip to content
Merged
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
21 changes: 21 additions & 0 deletions .github/fixtures/pelican-question-e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Dependencies, Chromium and a fixture-only CA are prepared before isolation.
# Build context is .github, not the application tree (whose .dockerignore excludes it).
ARG APP_IMAGE=pelican-app-base:unset
FROM mcr.microsoft.com/playwright:v1.56.1-noble AS runner
WORKDIR /opt/fixture
RUN npm install --no-save --ignore-scripts playwright@1.56.1 pg@8.16.3
RUN mkdir -p /opt/fixture/tls && \
openssl req -x509 -newkey rsa:2048 -nodes -days 7 \
-subj '/CN=fake-upstream' -addext 'subjectAltName=DNS:fake-upstream' \
-addext 'basicConstraints=critical,CA:TRUE' \
-keyout /opt/fixture/tls/key.pem -out /opt/fixture/tls/cert.pem && \
chmod 644 /opt/fixture/tls/key.pem
COPY scripts/pelican-question-e2e.mjs /opt/fixture/pelican-question-e2e.mjs
ENV NODE_EXTRA_CA_CERTS=/opt/fixture/tls/cert.pem
ENTRYPOINT ["node", "/opt/fixture/pelican-question-e2e.mjs"]

# Only add trust for this disposable fake-upstream certificate. Keep the real
# application binary, embedded frontend, resources and normal entrypoint.
FROM ${APP_IMAGE} AS app
COPY --from=runner /opt/fixture/tls/cert.pem /fixture-ca.pem
RUN cat /fixture-ca.pem >> /etc/ssl/certs/ca-certificates.crt
50 changes: 50 additions & 0 deletions .github/fixtures/pelican-question-e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Issue #795 隔离应用 E2E:手动链路与禁用分组计划

Refs #795。本目录只提供 CI fixture,不修改应用业务代码,不表示完整验收、真实模型兼容性或经验难度校准完成。逐场景状态由 `acceptance.json` 声明;脚本即使成功,也固定输出 `full_acceptance_complete: false`。

## 本增量的运行链

GitHub `pull_request`(base 为 `production`,包含 fixture/script/workflow 变动)即可触发本分支新工作流,Draft 不跳过。`workflow_dispatch` 只是工作流进入默认分支后的备用入口,不能假定新分支已经可 dispatch。父协调者负责 publication 和精确 head/check 回读。

`APP_SHA` 与 `HARNESS_SHA` 均显式取 PR head(dispatch 时取该事件 SHA),分别 checkout,记录 SHA/tree。`PARENT_BASE_SHA` 记录本轮父协调者提供的整合基线,绝不作为永久固定的被测旧应用 SHA。正常根 Dockerfile 构建嵌入前端的真实应用;浏览器/pg 依赖、镜像和 fixture CA 也全部在运行隔离前准备。运行期间 Compose 一次性内部网络上的应用、PostgreSQL、Redis、假上游和浏览器均无第二网络、host networking、宿主 Docker socket 或发布端口。宿主 CI 的 Docker inspect 只投影网络/端口/挂载/特权配置,不输出容器环境变量。

真实 AUTO_SETUP、迁移及虚构管理员正常登录后,SQL 只初始化两个 `anthropic/apikey` 账号和测试分组/关联,不插入题目、计划或结果。手动测试通过真实页面按钮、prepare API、handler/service 和上游 HTTP 请求执行,A/B 各两样本;输出唯一标记与上游去认证后的题面记录关联,再核真实 DOM 和 localStorage 刷新恢复。分组页面通过真实创建表单保存**禁用**计划并核对 API/PG,尚不执行调度。没有调用任何 `/run` 来代替 RunDue。

## HTTPS fixture 与原 HTTP 建议的差异

当前 `AccountTestService.validateUpstreamBaseURL` 在白名单启用时调用 `ValidateHTTPSURL`,不会读取 `allow_insecure_http` 来放行 HTTP。为保持真实校验启用,fixture 使用 `https://fake-upstream:4199`,临时生成仅含 fixture SAN 的证书,并仅在 CI fixture 镜像中加入该 CA。所有三类 URL host 白名单只列 `fake-upstream`,允许隔离私网,保持 HTTP 禁止。未关闭 TLS 校验、白名单或改动业务代码。该选择与 audit 中的 `http://` 提议不同,须在独审中确认;它不改变任何生产配置。

假上游只接受模型发现和 messages SSE,额外的健康、去认证 capture 读取及单次 refusal 控制端点仅供 fixture。可选 pricing 刷新明确返回 503,真实应用使用打包的 fallback 文件;未知路径/输入记录为拒绝并使浏览器验收失败。网页本身仅允许 app origin;provider 只能由应用调用,Node fixture 控制读取不伪装成浏览器请求。主防外呼边界是所有运行容器的 Docker internal 网络,虚构 key 不是防外呼措施。

## 未完成的完整验收范围

- [ ] A/B 账号随机定时计划由真实 UI 创建,各两个样本;只用限定 SQL 对齐同一 UTC 微秒 nominal time T,等待真正 runner/Claim。
- [ ] 四个账号结果的 PG 投影、去认证 payload、history list/detail API 和真实展开 DOM/iframe 按同一 plan/result ID 对账。
- [ ] 分组计划真实 RunDue/Claim、结果 PG → list/detail API → `PelicanTestsView` 同 ID 对账;不假设分组均匀路由 A/B。
- [ ] 经真实浏览器编辑计划后,旧 PG/API/UI 快照保持不变。
- [ ] 第二 nominal time T2 按现有哈希公式选到另一题,等待真实 tick,新旧记录共存;不能修改生产抽题算法。
- [ ] arm 单次 refusal 后真正产生 failed 持久化结果、失败历史及 lease 释放;现有 refusal server 能力尚未被此增量测试。
- [ ] 对结果/租约/到期字段进行限定 SQL 投影,与 API、capture 和场景 ID 关联。目前只有初始化实体与禁用分组计划投影,没有定时结果 SQL 证据。
- 远程 Actions、失败记录及当前 head 检查结论见 PR #809;场景结果以当次 artifact 为准。没有运行本地动态检查。
- [ ] 隔离链路真实截图上传 PR 原生附件并回读;现有组件 job 截图仍只是组件证据,不能混同此 job。无 PNG 提交到源码。
- [ ] 父协调者独审、完整技术验收与产品/经验难度证据。fixture 的简单 SVG 不代表题目作答合格或难度相当。

## 证据与清理

CI artifact 预期包含应用/harness SHA/tree、显式未完成清单、命名场景结果、网络结构投影、仅限 fixture 题面的 provider captures(无认证头/全量 body)、真实手动请求/题面投影、本轮 localStorage 结果投影、必要的实体/计划 PG 投影、浏览器错误/拒绝清单和截图。比较 `actual_prompt` 的边界是本 fixture 的 UTF-8 文本经过真实 service TrimSpace 后的发送值,不能外推任意输入。

不导出 auth token、Cookie、完整 HAR、数据库全表、凭据列、原始应用日志或真实用户数据。不把整个运行目录当附件。fixture 密码/key/CA 都是本轮自建假值,不能用到任何其他环境。失败时也留存上述受限产物,`always()` 销毁容器、网络和一次性卷,artifact 保留七天。父协调者首次远程运行前需审查此增量,发布后仍须按原 brief 继续同一 PR 的未完成范围。

## 证据目录权限

浏览器与假上游容器使用 CI runner 的 UID/GID,保持 `cap_drop: ALL` 和只读根文件系统。证据目录由同一 runner 创建,因此无需增加 DAC_OVERRIDE 或放宽目录权限。网络结构投影核对这两个容器的实际用户;浏览器启动失败也写入场景结果。

## 首次登录与支付 SDK

全新 fixture 正常完成引导退出与管理员声明确认,均由真实 UI 操作,不注入 localStorage 或伪造认证状态。登录 redirect 直接进入账号页,避免立即整页跳转取消初始化请求。隔离 job 同时发现 Airwallex SDK 被公共 vendor-misc 提前加载;本 PR 将该 SDK 独立分包,仍仅由现有支付页动态 import,账号页不应请求外部支付脚本。

管理员确认前已发出的页面读取会被真实合规中间件拒绝。脚本保留首次初始化阶段的错误列表,确认持久化后正常刷新页面,再对鹈鹕场景执行浏览器错误零值断言;不声称首次安装全过程无控制台错误。

分组计划场景从固定页面地址进入,再使用真实表单创建计划;不依赖当前管理员可定制的侧栏菜单展开/隐藏状态,也不声称已验收侧栏导航。

账号菜单保留原有滚动时关闭行为;harness 先滚动定位并等待绘制稳定,再打开菜单。仅菜单已消失时允许至多两次重新打开,次数写入 `menuReopens`;生成请求不会重试。
29 changes: 29 additions & 0 deletions .github/fixtures/pelican-question-e2e/acceptance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"scope": "initial-reviewable-increment",
"full_acceptance_complete": false,
"unimplemented": [
"account scheduled plans created via UI, two samples per A and B",
"same nominal UTC time, actual account runner Claim and four PG results",
"account PG result IDs and payloads reconciled with history/detail APIs and expanded real DOM",
"group due time alignment, real RunDue/Claim and PG/list/detail/DOM reconciliation",
"plan UI edit followed by proof old stored/API/DOM snapshot is unchanged",
"second nominal time mapped to a different question, new and old scheduled records coexist",
"deterministic upstream refusal yields failed persisted history and released lease",
"restricted result/lease/due SQL projections linked to captures and API IDs"
],
"pending_external_gates": [
"screenshots from successful isolated chain uploaded as PR native attachments and read back",
"product policy and empirical difficulty calibration; fixture output cannot prove either"
],
"fixture_transport_difference": "Uses fixture-only HTTPS and an ephemeral fixture CA, because the enabled real account-test URL allowlist calls ValidateHTTPSURL. The audit's proposed HTTP URL is not accepted with that allowlist enabled. No application validation is disabled or modified.",
"implemented_scenarios": [
"runtime internal Docker network for app, browser, fake provider, PostgreSQL and Redis",
"normal login and real accounts UI with original CSS",
"real prepare, account A and B with two samples each in one manual round",
"provider payload compared with API question and real DOM snapshot",
"manual localStorage recovery, history expansion and fixture iframe after reload",
"next manual round identity changes; repeated question selection is permitted",
"disabled group plan created through real browser form, create API and PG"
],
"verification_evidence": "Read scenario-results.json and the current PR head checks; this declaration does not assert runtime success."
}
109 changes: 109 additions & 0 deletions .github/fixtures/pelican-question-e2e/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# No service may gain a second network, host networking, published port, Docker
# socket, production config or persistent host data mount. Images are prebuilt.
x-runtime: &runtime
networks: [isolated]
restart: "no"
security_opt: [no-new-privileges:true]
cap_drop: [ALL]

services:
postgres:
<<: *runtime
image: postgres:18-alpine
environment:
POSTGRES_USER: fixture
POSTGRES_PASSWORD: fixture-only-postgres
POSTGRES_DB: fixture
volumes: [pg-data:/var/lib/postgresql]
# The stock entrypoint changes ownership before dropping privileges.
cap_add: [CHOWN, DAC_OVERRIDE, FOWNER, SETGID, SETUID]
healthcheck:
test: [CMD-SHELL, "pg_isready -U fixture -d fixture"]
interval: 2s
timeout: 3s
retries: 30
redis:
<<: *runtime
image: redis:7-alpine
command: [redis-server, --save, "", --appendonly, "no"]
tmpfs: [/data]
cap_add: [CHOWN, DAC_OVERRIDE, SETGID, SETUID]
healthcheck:
test: [CMD, redis-cli, ping]
interval: 2s
timeout: 3s
retries: 30
fake-upstream:
<<: *runtime
image: pelican-runner:${HARNESS_SHA:?required}
# Bind-mounted evidence belongs to the Actions runner; root has no DAC override.
user: "${FIXTURE_UID:?required}:${FIXTURE_GID:?required}"
command: [upstream]
read_only: true
volumes: ["${EVIDENCE_DIR:?required}:/evidence"]
healthcheck:
test: [CMD, node, /opt/fixture/pelican-question-e2e.mjs, upstream-health]
interval: 2s
timeout: 3s
retries: 30
app:
<<: *runtime
image: pelican-app:${APP_SHA:?required}
cap_add: [CHOWN, DAC_OVERRIDE, SETGID, SETUID]
environment:
AUTO_SETUP: "true"
ADMIN_EMAIL: reviewer@example.invalid
ADMIN_PASSWORD: Fixture-Only-795-Password!
JWT_SECRET: fixture-only-jwt-795-not-a-real-secret-0123456789abcdef
DATABASE_HOST: postgres
DATABASE_PORT: "5432"
DATABASE_USER: fixture
DATABASE_PASSWORD: fixture-only-postgres
DATABASE_DBNAME: fixture
DATABASE_SSLMODE: disable
REDIS_HOST: redis
SERVER_HOST: 0.0.0.0
SERVER_PORT: "8080"
SERVER_MODE: release
TZ: UTC
CONFIG_FILE: /fixture/config.yml
volumes:
- app-data:/app/data
- ./config.yml:/fixture/config.yml:ro
depends_on:
postgres: {condition: service_healthy}
redis: {condition: service_healthy}
fake-upstream: {condition: service_healthy}
healthcheck:
test: [CMD, wget, -q, -T, "3", -O, /dev/null, http://localhost:8080/health]
interval: 3s
timeout: 5s
retries: 60
browser:
<<: *runtime
image: pelican-runner:${HARNESS_SHA:?required}
# Bind-mounted evidence belongs to the Actions runner; root has no DAC override.
user: "${FIXTURE_UID:?required}:${FIXTURE_GID:?required}"
command: [browser]
read_only: true
shm_size: 1gb
tmpfs: [/tmp]
environment:
APP_ORIGIN: http://app:8080
PGHOST: postgres
PGUSER: fixture
PGPASSWORD: fixture-only-postgres
PGDATABASE: fixture
volumes:
- "${EVIDENCE_DIR:?required}:/evidence"
- ./acceptance.json:/fixture/acceptance.json:ro
depends_on:
app: {condition: service_healthy}

networks:
isolated:
internal: true
enable_ipv6: false
volumes:
pg-data:
app-data:
15 changes: 15 additions & 0 deletions .github/fixtures/pelican-question-e2e/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Fixture only; AUTO_SETUP writes its own temporary /app/data/config.yaml.
# Environment supplies server/database/redis/JWT fields for normal config load.
security:
url_allowlist:
enabled: true
upstream_hosts: [fake-upstream]
pricing_hosts: [fake-upstream]
crs_hosts: [fake-upstream]
allow_private_hosts: true
allow_insecure_http: false
# No SMTP configuration. Background downloads fail closed on the internal network.
# Use the real packaged pricing fallback; no fake pricing endpoint is served.
pricing:
remote_url: https://fake-upstream:4199/disabled-pricing
hash_url: https://fake-upstream:4199/disabled-pricing-hash
19 changes: 19 additions & 0 deletions .github/fixtures/pelican-question-e2e/seed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Run only after the actual application has completed its normal migrations.
-- SQL initializes fictional entities only: no plans, questions or result rows.
BEGIN;
INSERT INTO groups (name, platform, status)
VALUES ('fixture-pelican-group', 'anthropic', 'active');

INSERT INTO accounts (name, platform, type, credentials, concurrency, priority, status, schedulable)
SELECT 'fixture-pelican-' || alias, 'anthropic', 'apikey',
jsonb_build_object('api_key', 'fixture-only-key-' || alias,
'base_url', 'https://fake-upstream:4199'),
4, 50, 'active', true
FROM (VALUES ('a'), ('b')) AS fixtures(alias);

INSERT INTO account_groups (account_id, group_id)
SELECT a.id, g.id
FROM accounts a CROSS JOIN groups g
WHERE a.name IN ('fixture-pelican-a', 'fixture-pelican-b')
AND g.name = 'fixture-pelican-group';
COMMIT;
Loading
Loading