Skip to content
Draft
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
62 changes: 15 additions & 47 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,50 +43,18 @@ jobs:

- run: pnpm --filter @deva/desktop build:headless && node --test apps/desktop/test/{headless-chat,project-docs-mount}.test.mjs

- name: Verify native amd64 Compose chat continuity and optional document grant then revocation
timeout-minutes: 12
env:
DEVA_PORT: '18794'
DEVA_ORIGIN: http://127.0.0.1:18794
DEVA_MODEL_BASE_URL: http://127.0.0.1:18795/v1
DEVA_MODEL: deva-compose-fixture
DEVA_MODEL_PROTOCOL: responses
run: |
set -eu
test "$(uname -m)" = x86_64
node --test apps/desktop/test/headless-compose-default.test.mjs
export COMPOSE_PROJECT_NAME="deva-test-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
DEVA_WEB_TOKEN=$(openssl rand -hex 32); export DEVA_WEB_TOKEN
# Private synthetic input stays outside the checkout/build context. The digest is fixed separately.
stage=$(mktemp -d "${RUNNER_TEMP:?}/deva-docs-XXXXXXXX")
export DEVA_PROJECT_DOCS_FILE="$stage/reviewed.json"
cleanup() {
docker compose -f compose.yaml down --volumes
test "$(realpath "$stage")" = "$stage" && test "$(dirname "$stage")" = "$RUNNER_TEMP"
if test -f "$stage/reviewed.json"; then test "$(realpath "$stage/reviewed.json")" = "$stage/reviewed.json" && unlink "$stage/reviewed.json"; fi
rmdir "$stage"
}
trap cleanup EXIT
printf '%s\n' '{"version":1,"project":"发布手册","documents":[{"name":"入门.md","text":"首次使用:先阅读版本说明。\n"}]}' > "$DEVA_PROJECT_DOCS_FILE"
chmod 0444 "$DEVA_PROJECT_DOCS_FILE"
export DEVA_PROJECT_DOCS_SHA256=17abef945c4669dcd7d6162cd1dd65084490d4249b1b6c6b9b8bf477ba0879f5
with_docs() { docker compose -f compose.yaml -f compose.project-docs.yaml "$@"; }
docker compose up --build --wait --wait-timeout 90
curl -fsS "$DEVA_ORIGIN/healthz"
first=$(docker compose ps -q deva)
sid=$(docker compose exec -T -e DEVA_SMOKE_EXPECT_PROTOCOL=responses deva node --input-type=module < apps/desktop/test/headless-compose-probe.mjs)
export DEVA_MODEL_PROTOCOL=anthropic
with_docs up --no-build --force-recreate --wait --wait-timeout 90
second=$(with_docs ps -q deva)
test -n "$first" && test -n "$second" && test "$first" != "$second"
test "$(docker inspect -f '{{range .Mounts}}{{if eq .Destination "/run/deva-project-docs/snapshot.json"}}{{.Type}}:{{.RW}}{{end}}{{end}}' "$second")" = bind:false
test "$(with_docs exec -T deva id -u)" = 1000
doc=$(with_docs exec -T -e DEVA_SMOKE_SESSION="$sid" deva node --input-type=module < apps/desktop/test/headless-compose-docs-probe.mjs)
with_docs exec -T -e DEVA_SMOKE_EXPECT_PROTOCOL=anthropic -e DEVA_SMOKE_SESSION="$sid" deva node --input-type=module < apps/desktop/test/headless-compose-probe.mjs
with_docs stop deva
test "$(docker inspect -f '{{.State.Running}}' "$second")" = false
unset DEVA_PROJECT_DOCS_FILE DEVA_PROJECT_DOCS_SHA256
docker compose -f compose.yaml up --no-build --force-recreate --wait --wait-timeout 90
third=$(docker compose ps -q deva)
test -n "$third" && test "$third" != "$second"
docker compose exec -T -e DEVA_SMOKE_SESSION="$sid" -e DEVA_REVOKED_DOC="$doc" deva node --input-type=module < apps/desktop/test/headless-compose-docs-probe.mjs
- name: Check manifest isolation and qualification guards
run: node --test apps/desktop/test/{headless-compose-default,compose-acceptance-host,compose-acceptance-evidence,compose-acceptance-lifecycle,native-compose-entry}.test.mjs

- name: Qualify the native amd64 Compose image and verify cleanup
timeout-minutes: 20
shell: bash
run: node apps/desktop/test/verify-native-compose.mjs | tee "$RUNNER_TEMP/deva-native-amd64.json"

- name: Save the successful native image receipt
uses: actions/upload-artifact@v4
with:
name: deva-native-amd64-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/deva-native-amd64.json
if-no-files-found: error
retention-days: 14
19 changes: 19 additions & 0 deletions apps/desktop/src/headless/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ docker compose -f compose.yaml -f compose.project-docs.yaml stop deva &&

换版亦先停旧服务,用新文件、新的已审核摘要重新发布。仅替换或删除宿主原文件不会改变正在运行的快照。重新登录后旧文档 ID 失效,关闭资料时原有聊天仍可续聊。更多授权边界与验收条件见[只读资料设计](./project-docs-design.md)。

## 原生 amd64 Docker 成品验收

这是验收已提交版本的命令,不是日常部署命令。在**原生 x86-64 Linux** 上检出要验证的提交,使用 Node 22 或更新版本、Git、可访问的本地 Docker Engine 和 Compose v2+。无需安装项目依赖、提供模型密钥或复用正在运行的 Deva 实例。

```bash
# 只读检查架构、本地引擎和 Compose。成功也不代表容器已经运行。
node apps/desktop/test/verify-native-compose.mjs --preflight
# 实际构建和启动三次,清理完成后向标准输出写一条 JSON 回执。
node apps/desktop/test/verify-native-compose.mjs
```

[验收程序](../../test/verify-native-compose.mjs)从 Git 提交对象导出构建所需文件,使用一次性项目名、独立数据卷和动态宿主回环端口。它不会使用工作目录的 `.env`、未提交的文件、原有服务令牌或外部模型。首次构建仍需能获取基础镜像与锁定的依赖。不同 Compose 版本会省略不同的布尔默认值;程序在启动前用当前 CLI 对照渲染 `create_host_path` 的两个取值,只有原始的禁止自动创建配置用于实际运行。运行顺序是:

1. 基础实例用 Responses 协议完成含附件的第一轮;第二轮模型夹具只发一段文字,保持连接。在用户接口确认这段文字后发出 Stop,验证真实上游 TCP 连接在夹具主动结束前断开,并保存部分回复。
2. 用同一镜像和数据卷重建,改用 Anthropic 协议并授权一份只读快照;旧登录须失效,新登录可打开合成文档。模型实际收到的续聊历史须含原附件和刚刚停止的文字。
3. 停止已授权实例,撤下挂载,再用基础配置重建。旧文档 ID 返回 `404`;在原会话上用默认的 OpenAI Chat Completions 协议再发一条消息,须收到实际回复。三次启动均须从宿主发布的回环端口验证健康和登录,且容器 ID 各异、镜像 ID 一致、使用原命名卷。

**通过标准是退出码为 `0` 且回执为 `kind: deva-native-compose-v1`、`status: passed` 和 `cleanup: verified`。** 回执记录实际检出的 Git 提交、镜像内容 ID、三个容器 ID 与引擎版本,不含令牌、Cookie、文档 ID 或正文。程序只清理本次已核对归属的容器、网络、卷、镜像标签和暂存目录,不清空共享构建缓存。失败会在标准错误报告阶段与原因;预检、ARM64 运行、模拟输入测试、仅解析 Compose 配置都不是成品回执。CI 使用同一命令,只上传成功回执。

## 从源码验证

```bash
Expand Down
164 changes: 164 additions & 0 deletions apps/desktop/test/compose-acceptance-evidence.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { posix } from 'node:path'
import { isDeepStrictEqual } from 'node:util'

const containerIdPattern = /^[a-f0-9]{64}$/
const imageIdPattern = /^sha256:[a-f0-9]{64}$/
const projectPattern = /^deva-accept-[a-f0-9]{24}$/
const volumePattern = /^deva-accept-[a-f0-9]{24}_deva-data$/
const nodePattern = /^v22\.(?:0|[1-9]\d{0,2})\.(?:0|[1-9]\d{0,2})$/
const enginePattern = /^\d{1,3}\.\d{1,3}\.\d{1,4}(?:[-+][a-zA-Z0-9]+(?:[.+~-][a-zA-Z0-9]+)*)?$/
const snapshotTarget = '/run/deva-project-docs/snapshot.json'
const matches = (pattern, value) => typeof value === 'string' && pattern.test(value)
const x86 = value => value === 'amd64' || value === 'x86_64'
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value)
const emptyList = value => value == null || (Array.isArray(value) && value.length === 0)
const emptyMap = value => value == null || (record(value) && Object.keys(value).length === 0)
const onlyKeys = (value, allowed) => record(value) && Object.keys(value).every(key => allowed.includes(key))
const unsetOr = (value, expected) => value === undefined || value === expected
const exactListValue = (value, expected) => Array.isArray(value) && value.length === 1 && expected.includes(value[0])
const noNewPrivileges = ['no-new-privileges:true', 'no-new-privileges=true']
const validPort = value => Number.isInteger(value) && value > 0 && value <= 65535
const absolute = value => typeof value === 'string' && posix.isAbsolute(value) && posix.normalize(value) === value &&
!value.endsWith('/') && !/[\x00-\x1f\x7f]/.test(value)
const privateSource = value => absolute(value) && posix.dirname(value) !== '/'

function requireEvidence(condition, reason) {
if (!condition) throw new Error(reason)
}

export function checkEngine(info) {
const { OSType, Architecture, ServerVersion } = info ?? {}
requireEvidence(OSType === 'linux', 'engine.os')
requireEvidence(x86(Architecture), 'engine.architecture')
requireEvidence(matches(enginePattern, ServerVersion) && ServerVersion.length <= 64, 'engine.version')
return ServerVersion
}

const planServiceKeys = ['build', 'cap_drop', 'command', 'entrypoint', 'environment', 'networks', 'ports',
'read_only', 'restart', 'security_opt', 'volumes', 'privileged']
const planEnvironmentKeys = ['DEVA_HOST', 'DEVA_PORT', 'DEVA_ORIGIN', 'DEVA_WEB_TOKEN', 'DEVA_MODEL_PROTOCOL',
'DEVA_MODEL_BASE_URL', 'DEVA_MODEL', 'DEVA_MODEL_API_KEY']

export function checkPlan(plan, options) {
const { project, port, work, snapshotFile, granted } = options ?? {}
requireEvidence(matches(projectPattern, project) && validPort(port) && absolute(work) &&
typeof granted === 'boolean' && (!granted || privateSource(snapshotFile)), 'plan.inputs')
requireEvidence(onlyKeys(plan, ['name', 'services', 'networks', 'volumes']) && plan.name === project &&
onlyKeys(plan.services, ['deva']) && onlyKeys(plan.services.deva, planServiceKeys), 'plan.services')
const service = plan.services.deva
const { build, environment: env } = service
requireEvidence(onlyKeys(build, ['context', 'dockerfile']) && build.context === work &&
(unsetOr(build.dockerfile, 'Dockerfile') || build.dockerfile === posix.join(work, 'Dockerfile')), 'plan.build')
const envKeys = granted ? [...planEnvironmentKeys, 'DEVA_PROJECT_DOCS_SHA256'] : planEnvironmentKeys
requireEvidence(onlyKeys(env, envKeys) && envKeys.every(key => typeof env[key] === 'string') &&
(!granted || matches(containerIdPattern, env.DEVA_PROJECT_DOCS_SHA256)), 'plan.environment')
requireEvidence(service.read_only === true && unsetOr(service.privileged, false) && service.restart === 'unless-stopped' &&
exactListValue(service.cap_drop, ['ALL']) && exactListValue(service.security_opt, noNewPrivileges) &&
service.command == null && service.entrypoint == null, 'plan.runtime')

const network = plan.networks?.default, attached = service.networks
requireEvidence(onlyKeys(plan.networks, ['default']) && onlyKeys(network, ['name', 'driver', 'external', 'ipam']) &&
network.name === `${project}_default` && unsetOr(network.driver, 'bridge') && unsetOr(network.external, false) &&
emptyMap(network.ipam) && (attached === undefined || (onlyKeys(attached, ['default']) &&
Object.hasOwn(attached, 'default') && emptyMap(attached.default))), 'plan.network')
const volume = plan.volumes?.['deva-data']
requireEvidence(onlyKeys(plan.volumes, ['deva-data']) && onlyKeys(volume, ['name', 'driver', 'external', 'driver_opts']) &&
volume.name === `${project}_deva-data` && unsetOr(volume.driver, 'local') && unsetOr(volume.external, false) &&
emptyMap(volume.driver_opts), 'plan.volume')

const publication = service.ports?.[0]
requireEvidence(Array.isArray(service.ports) && service.ports.length === 1 &&
onlyKeys(publication, ['host_ip', 'target', 'published', 'protocol', 'mode']) && publication.host_ip === '127.0.0.1' &&
publication.target === port && [String(port), port].includes(publication.published) &&
unsetOr(publication.protocol, 'tcp') && unsetOr(publication.mode, 'ingress'), 'plan.ports')
const mounts = service.volumes
requireEvidence(Array.isArray(mounts) && mounts.length === (granted ? 2 : 1), 'plan.mounts')
const data = mounts.find(mount => mount?.target === '/data')
requireEvidence(onlyKeys(data, ['type', 'source', 'target', 'volume', 'read_only']) && data.type === 'volume' &&
data.source === 'deva-data' && emptyMap(data.volume) && unsetOr(data.read_only, false), 'plan.mounts')
if (granted) {
const bind = mounts.find(mount => mount?.target === snapshotTarget)
requireEvidence(onlyKeys(bind, ['type', 'source', 'target', 'bind', 'read_only']) && bind.type === 'bind' &&
bind.source === snapshotFile && bind.read_only === true && onlyKeys(bind.bind, ['propagation', 'create_host_path']) &&
bind.bind.propagation === 'rprivate' && unsetOr(bind.bind.create_host_path, false), 'plan.snapshot')
}
}

// A config-only contrast: Compose v2.36 omits false; v5.7 omits true. Absence by itself proves neither.
export function sourceCreationControl(yaml) {
const declaration = /^([ \t]*create_host_path:[ \t]*)false[ \t]*$/gmu
requireEvidence(typeof yaml === 'string' && [...yaml.matchAll(declaration)].length === 1, 'plan.source-control')
return yaml.replace(declaration, '$1true')
}
export function checkSourceCreationControl(plan, control) {
const leaf = p => p?.services?.deva?.volumes?.find(v => v?.type === 'bind' && v.target === snapshotTarget)?.bind
const a = leaf(plan), b = leaf(control)
requireEvidence(record(a) && record(b) && unsetOr(a.create_host_path, false) && unsetOr(b.create_host_path, true) &&
a.create_host_path !== b.create_host_path, 'plan.source-control')
const adjusted = structuredClone(control), test = leaf(adjusted)
if (Object.hasOwn(a, 'create_host_path')) test.create_host_path = a.create_host_path
else delete test.create_host_path
requireEvidence(isDeepStrictEqual(plan, adjusted), 'plan.source-control')
}

function exactPort(bindings, port, allowUnpublished = false) {
if (!record(bindings)) return false
const key = `${port}/tcp`
const rows = bindings[key]
// Docker may include unbound image EXPOSE entries with null or empty bindings.
return Object.keys(bindings).every(name => name === key || (allowUnpublished && emptyList(bindings[name]))) &&
Array.isArray(rows) && rows.length === 1 && rows[0]?.HostIp === '127.0.0.1' && rows[0]?.HostPort === String(port)
}

export function checkStage(evidence) {
const { container, image, node, project, port, snapshotFile, granted } = evidence ?? {}
requireEvidence(matches(projectPattern, project), 'stage.project')
requireEvidence(record(container) && matches(containerIdPattern, container.Id), 'stage.container-id')
requireEvidence(record(image) && matches(imageIdPattern, image.Id) && container.Image === image.Id, 'stage.image')
requireEvidence(image.Os === 'linux' && x86(image.Architecture) &&
(container.Platform === undefined || container.Platform === 'linux'), 'stage.platform')
requireEvidence(node?.os === 'linux' && node.arch === 'x64' && node.uid === 1000 &&
matches(nodePattern, node.version), 'stage.node')
const { State: state, HostConfig: host, Config: config, NetworkSettings: network, Mounts: mounts } = container
const health = state?.Health
requireEvidence(state?.Running === true && state.Status === 'running' && !state.Paused && !state.Restarting &&
health?.Status === 'healthy' && health.FailingStreak === 0 && Array.isArray(health.Log) &&
health.Log.at(-1)?.ExitCode === 0, 'stage.health')
requireEvidence(config?.Labels?.['com.docker.compose.project'] === project &&
config.Labels['com.docker.compose.service'] === 'deva', 'stage.labels')
requireEvidence(host?.ReadonlyRootfs === true && host.Privileged === false && emptyList(host.CapAdd) &&
exactListValue(host.CapDrop, ['ALL']) && exactListValue(host.SecurityOpt, noNewPrivileges), 'stage.hardening')
requireEvidence(emptyList(host.Devices) && emptyList(host.DeviceRequests) &&
emptyList(host.DeviceCgroupRules), 'stage.devices')
const networkName = `${project}_default`, attached = network?.Networks
requireEvidence(host.NetworkMode === networkName && (attached === undefined ||
(onlyKeys(attached, [networkName]) && Object.hasOwn(attached, networkName))), 'stage.network')
requireEvidence(validPort(port) && !host.PublishAllPorts &&
exactPort(network?.Ports, port, true) &&
(host.PortBindings === undefined || exactPort(host.PortBindings, port)), 'stage.ports')

requireEvidence(typeof granted === 'boolean' && emptyMap(host.Tmpfs) && emptyList(host.VolumesFrom) &&
Array.isArray(mounts) && mounts.length === (granted ? 2 : 1), 'stage.mounts')
const volumeName = `${project}_deva-data`
const volume = mounts.find(mount => mount?.Destination === '/data')
requireEvidence(volume?.Type === 'volume' && volume.Name === volumeName && volume.RW === true &&
(volume.Driver === undefined || volume.Driver === 'local'), 'stage.volume')
if (granted) {
const bind = mounts.find(mount => mount?.Destination === snapshotTarget)
// The caller creates and checks the private source on disk; inspect proves the exact leaf was mounted.
requireEvidence(privateSource(snapshotFile) && bind?.Type === 'bind' && bind.Source === snapshotFile &&
bind.RW === false && unsetOr(bind.Propagation, 'rprivate'), 'stage.snapshot')
}
return { containerId: container.Id, imageId: image.Id, volumeName, nodeVersion: node.version }
}

export function checkContinuity(stages) {
requireEvidence(Array.isArray(stages) && stages.length === 3 && Array.from(stages).every(stage =>
record(stage) && matches(containerIdPattern, stage.containerId) && matches(imageIdPattern, stage.imageId) &&
matches(volumePattern, stage.volumeName) && matches(nodePattern, stage.nodeVersion)), 'continuity.stages')
const [first, ...rest] = stages
requireEvidence(new Set(stages.map(stage => stage.containerId)).size === 3, 'continuity.containers')
requireEvidence(rest.every(stage => stage.imageId === first.imageId), 'continuity.image')
requireEvidence(rest.every(stage => stage.volumeName === first.volumeName), 'continuity.volume')
requireEvidence(rest.every(stage => stage.nodeVersion === first.nodeVersion), 'continuity.node')
}
Loading