diff --git a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.i18n.yaml b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.i18n.yaml index e3d96b6365..1b6639b303 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write .agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.md -2026-09-09-consumer-owned-startup-strictness.md: 8e3d5f0141245ba2fa2c85faba607ac1be952e37 -2026-09-09-consumer-owned-startup-strictness.zh.md: 3873b9ceeb6204939e817a53514f5e18767ececc +2026-09-09-consumer-owned-startup-strictness.md: e009e66ead25ef0a5e6001d33663e32bc04d19d2 +2026-09-09-consumer-owned-startup-strictness.zh.md: 58c364056f5b0dc41e018cd5488be983662401d4 diff --git a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.md b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.md index 8e3d5f0141..e009e66ead 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.md +++ b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.md @@ -33,3 +33,7 @@ Stable required entry ids are part of application assembly. Renaming one require ## Testing App-boot unit tests cover absent and disabled required ids, optional import failure, config evaluation failure, synchronous and asynchronous `apply()` failure, pending dependencies, and required failure teardown. The built Web-profile acceptance serves the full UI with optional failures and exits nonzero without readiness when the required HTTP port is occupied or `modules` or `connection` cannot activate. + +The [Web process matrix](../../../../apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts) independently exercises optional and required failures at startup and after native patch-file edits. Authenticated HTTP requests and plugin lifecycle files distinguish a usable application from a surviving process. These keyless process checks complement the [controlled-delivery unit tests](../testing/2026-09-09-user-patch-hmr-test-delivery.md): unit tests isolate reconciliation failures, while the process tests also require the shipped launcher, native watcher, and bounded shutdown to work together. + +The matrix enables Chokidar's `awaitWriteFinish` to acknowledge stable file contents before each reload; otherwise its short change-event suppression window can discard the next test edit. Native events remain required, and assertions wait for observed activation or failure rather than a fixed settling sleep. This is explicit test configuration, not evidence for the default watcher timing. diff --git a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.zh.md b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.zh.md index 3873b9ceeb..58c364056f 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.zh.md +++ b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.zh.md @@ -33,3 +33,7 @@ Required id 为 `agent-loop`、`webserver`、`modules`、`connection`、`headles ## 测试 App-boot 单元测试覆盖缺失和禁用的 required id、optional import failure、config evaluation failure、同步和异步 `apply()` failure、pending dependency,以及 required failure teardown。构建后的 Web-profile acceptance 会在 optional failure 存在时继续提供完整 UI,并在 required HTTP port 被占用或 `modules`、`connection` 无法激活时以非零码退出,且不报告就绪。 + +[Web 进程矩阵](../../../../apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts)分别验证启动时和原生补丁文件修改后的 optional 与 required 失败。经过认证的 HTTP 请求和插件生命周期文件区分可用应用与仅存活的进程。这些无需密钥的进程检查与[受控事件投递单元测试](../testing/2026-09-09-user-patch-hmr-test-delivery.zh.md)互补:单元测试隔离配置协调失败,进程测试还要求随附启动器、原生监听器和有界关闭流程协同工作。 + +矩阵启用 Chokidar 的 `awaitWriteFinish`,在每次重载前确认文件内容已稳定;否则它的短暂 change 事件抑制窗口可能丢弃下一次测试编辑。测试仍然依赖原生事件,并等待观察到激活或失败,而不是固定时长的休眠。这是显式测试配置,不能证明默认监听器的时序行为。 diff --git a/apps/cli/README.i18n.yaml b/apps/cli/README.i18n.yaml index cfded686cf..34a8598bdc 100644 --- a/apps/cli/README.i18n.yaml +++ b/apps/cli/README.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write apps/cli/README.md -README.md: 2e74ef68cf0b8487083a2e2af0f5175c78ec5212 -README.zh.md: 553f28f3af78b18658701449678de80b086dbb15 +README.md: cfab7a4983c31a21b68157c9cefb38c1654571ff +README.zh.md: 67d07fba1fc27bca9c2a696daddde88aac3aa39c diff --git a/apps/cli/README.md b/apps/cli/README.md index 2e74ef68cf..cfab7a4983 100644 --- a/apps/cli/README.md +++ b/apps/cli/README.md @@ -2,7 +2,7 @@ English | [中文](README.zh.md) -The `dsh` command is the sole supported Node application launcher: profiles are ordered stacks of plugin-bundle patch layers under the user's own overrides. SDK and ACP are profiles, not separate public bins. The Python runtime wheel packages this same command; the SDK defaults to `sdk`, and the minimal example selects `sdk-minimal`. [`src/args.ts`](src/args.ts) owns the command grammar, and [`src/bin.ts`](src/bin.ts) loads only the selected runner. Invalid commands, options from another mode, configuration errors, and boot failures exit nonzero. +The `dsh` command is the sole supported Node application launcher: profiles are ordered stacks of plugin-bundle patch layers under the user's own overrides. SDK and ACP are profiles, not separate public bins. The Python runtime wheel packages this same command; the SDK defaults to `sdk`, and the minimal example selects `sdk-minimal`. [`src/args.ts`](src/args.ts) owns the command grammar, and [`src/bin.ts`](src/bin.ts) loads only the selected runner. Invalid commands, options from another mode, and fatal configuration or boot failures exit nonzero. ## Entry modes @@ -45,7 +45,7 @@ Bundles named in `dsh.profile.bundles` resolve from the dsh installation first ( Use `--dump-default-config` and `--dump-config` to inspect the composed tree without booting it. -The [CLI behavior reference](reference/README.md) owns exact layer precedence, flags, shutdown behavior, deployment defaults, and source execution. +The [CLI behavior reference](reference/README.md) owns exact layer precedence, flags, shutdown behavior, deployment defaults, and source execution. The [startup and reload failure table](../../packages/boot/app-boot/README.md#startup-and-reload-failures) compares optional and required plugin failures with configuration HMR. ## Optional overlays @@ -54,3 +54,5 @@ The [CLI behavior reference](reference/README.md) owns exact layer precedence, f ## Development Production runs require built package and frontend artifacts. From the repository root, run `pnpm run build` separately, then use `pnpm dsh ` to run the TypeScript entry and forward every argument; the [source-execution reference](reference/README.md#source-execution) owns the module-resolution contract. + +The [Web failure matrix](tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts) runs the built CLI through startup failures and native configuration HMR with `awaitWriteFinish` enabled in `test:expected`. It verifies authenticated HTTP responses, diagnostics, recovery, process exits, and disposal without model API calls; the [startup acceptance](tests/profiles/web/tests/web-best-effort-startup.expected.e2e.ts) also covers the shipped required Web dependencies and port conflicts. diff --git a/apps/cli/README.zh.md b/apps/cli/README.zh.md index 553f28f3af..67d07fba1f 100644 --- a/apps/cli/README.zh.md +++ b/apps/cli/README.zh.md @@ -2,7 +2,7 @@ [English](README.md) | 中文 -`dsh` 是唯一受支持的 Node 应用启动器;profile 由多个插件组合包 patch 层按顺序叠加而成,其上再应用用户自己的覆盖配置。SDK 与 ACP(Agent Client Protocol)都是 profile,而不是独立的公开可执行命令。Python 运行时 wheel 包中也包含同一个命令;SDK 默认使用 `sdk`,极简示例选择 `sdk-minimal`。[`src/args.ts`](src/args.ts) 负责命令语法,[`src/bin.ts`](src/bin.ts) 只加载选中的运行器。无效命令、来自其他模式的选项、配置错误和启动失败都会以非零状态退出。 +`dsh` 是唯一受支持的 Node 应用启动器;profile 由多个插件组合包 patch 层按顺序叠加而成,其上再应用用户自己的覆盖配置。SDK 与 ACP(Agent Client Protocol)都是 profile,而不是独立的公开可执行命令。Python 运行时 wheel 包中也包含同一个命令;SDK 默认使用 `sdk`,极简示例选择 `sdk-minimal`。[`src/args.ts`](src/args.ts) 负责命令语法,[`src/bin.ts`](src/bin.ts) 只加载选中的运行器。无效命令、来自其他模式的选项,以及致命的配置或启动错误都会以非零状态退出。 ## 入口模式 @@ -45,7 +45,7 @@ profile 目录包含一个 `package.json`,其中记录树外插件依赖,以 使用 `--dump-default-config` 和 `--dump-config` 可在不启动的情况下检查组合后的配置树。 -层的确切优先级、flag、关闭行为、部署默认值和源码执行方式,以 [CLI 行为参考](reference/README.zh.md)为准。 +层的确切优先级、flag、关闭行为、部署默认值和源码执行方式,以 [CLI 行为参考](reference/README.zh.md)为准。[启动与重载失败表](../../packages/boot/app-boot/README.zh.md#startup-and-reload-failures)对比 optional、required 插件启动失败与配置 HMR 的行为。 ## 可选覆盖层 @@ -54,3 +54,5 @@ profile 目录包含一个 `package.json`,其中记录树外插件依赖,以 ## 开发 生产运行需要已构建的包与前端产物。请在仓库根目录单独运行 `pnpm run build`,然后使用 `pnpm dsh ` 运行 TypeScript 入口并转发所有参数;模块解析约定以[源码执行参考](reference/README.zh.md#source-execution)为准。 + +[Web 失败矩阵](tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts)在 `test:expected` 中通过构建后的 CLI 验证启动失败与启用 `awaitWriteFinish` 的原生配置 HMR。它不调用模型 API,而是检查经过认证的 HTTP 响应、诊断、恢复、进程退出与 dispose;[启动验收测试](tests/profiles/web/tests/web-best-effort-startup.expected.e2e.ts)还覆盖随附 Web 的必需依赖与端口冲突。 diff --git a/apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts b/apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts new file mode 100644 index 0000000000..d2d14a5ada --- /dev/null +++ b/apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts @@ -0,0 +1,404 @@ +/** Failure policy through the built Web process and native configuration watcher. */ + +import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { createServer } from 'node:http' +import { join } from 'node:path' +import { fileURLToPath, pathToFileURL } from 'node:url' +import { execa } from 'execa' +import { describe, expect, it } from 'vitest' +import { FiberState } from '@deepseek-ai/cordis' + +const repoRoot = fileURLToPath(new URL('../../../../../../', import.meta.url)) +const bin = join(repoRoot, 'apps/cli/lib/bin.js') +const built = existsSync(bin) && existsSync(join(repoRoot, 'apps/web/dist/index.html')) +const failures = [ + ['import', 'missing.mjs'], + ['module evaluation', 'matrix module evaluation'], + ['schema', 'matrix schema failure'], + ['config expression', 'matrix config expression'], + ['disabled expression', 'matrix disabled expression'], + ['sync apply', 'matrix sync apply'], + ['async apply', 'matrix async apply'], + ['dependency', 'matrixMissingService'], +] as const +type Failure = typeof failures[number][0] + +function fixture() { + const root = mkdtempSync(join(tmpdir(), 'dsh-web-failure-matrix-')) + const home = join(root, 'home') + mkdirSync(home) + const events = join(root, 'events') + const diagnostics = join(root, 'diagnostics') + const serverUrl = join(root, 'server-url') + const states = join(root, 'states') + const stop = join(root, 'stop') + const patch = join(home, 'cordis.patch.yml') + const watcher = join(root, 'watcher.patch.yml') + // Native delivery remains real; completed writes bypass Chokidar's 50 ms change suppression. + writeFileSync(watcher, JSON.stringify([{ id: 'hmr', disabled: false, config: { + root: [], awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 20 }, + } }]) + '\n') + writeFileSync(events, '') + writeFileSync(diagnostics, '') + writeFileSync(states, '{}') + const observerPath = join(root, 'observer.mjs') + // HMR reports through Cordis logger exporters; WARN is above their default INFO threshold. + writeFileSync(observerPath, [ + "import { appendFileSync, writeFileSync, renameSync, rmSync } from 'node:fs'", + "import { inspect } from 'node:util'", + 'export function apply(ctx, config) {', + ' const report = message => appendFileSync(config.path, message.args.map(arg => inspect(arg)).join(" ") + "\\n")', + ' ctx.logger.buffer.forEach(report)', + ' ctx.logger.exporter({ levels: { default: 3 }, export: report })', + ' const timer = setInterval(() => {', + ' const loader = ctx.get("loader")', + ' if (!loader) return', + ' writeFileSync(config.states + ".tmp", JSON.stringify(Object.fromEntries([...loader.entries()].map(entry => [entry.options.id, entry.fiber?.state]))))', + ' renameSync(config.states + ".tmp", config.states)', + ' }, 20)', + ' ctx.effect(() => () => { clearInterval(timer) })', + ' ctx.inject(["webServer", "connection"], scope => {', + ' writeFileSync(config.url, scope.connection.authenticatedUrl(`http://127.0.0.1:${scope.webServer.port}`))', + ' scope.effect(() => () => { rmSync(config.url, { force: true }) })', + ' })', + '}', + '', + ].join('\n')) + const observer = { id: 'matrix-log-observer', name: pathToFileURL(observerPath).href, config: { path: diagnostics, url: serverUrl, states } } + const plugin = join(root, 'probe.mjs') + writeFileSync(plugin, [ + "import { appendFileSync, existsSync } from 'node:fs'", + 'export const Config = { "~standard": { version: 1, vendor: "matrix", validate(value) {', + ' return value.mode === "schema" ? { issues: [{ message: "matrix schema failure" }] } : { value }', + '} } }', + 'export const apply = (ctx, config) => {', + ' if (config.mode === "sync apply") throw new Error("matrix sync apply")', + ' return activate(ctx, config)', + '}', + 'async function activate(ctx, config) {', + ' if (config.mode === "async apply") { await Promise.resolve(); throw new Error("matrix async apply") }', + ' if (config.provider) ctx.provide(config.provider, true)', + ' if (config.mode === "detached") setImmediate(() => { void Promise.reject(new Error("matrix detached failure")) })', + ' appendFileSync(config.events, `${config.label} apply ${config.generation}\\n`)', + ' const timer = setInterval(() => { if (existsSync(config.stop)) process.emit("SIGTERM") }, 20)', + ' ctx.effect(() => () => { clearInterval(timer); appendFileSync(config.events, `${config.label} dispose ${config.generation}\\n`) })', + '}', + '', + ].join('\n')) + writeFileSync(join(root, 'evaluation.mjs'), 'throw new Error("matrix module evaluation")\n') + const url = pathToFileURL(plugin).href + const config = (label: string, generation: number, mode = '') => ({ label, generation, mode, events, stop }) + const witness = (generation: number) => ({ id: 'matrix-witness', name: url, config: config('witness', generation) }) + const target = (id: string, failure?: Failure, generation = 1) => ({ + id, + name: failure === 'import' ? pathToFileURL(join(root, 'missing.mjs')).href + : failure === 'module evaluation' ? pathToFileURL(join(root, 'evaluation.mjs')).href : url, + ...(failure === 'dependency' ? { inject: ['matrixMissingService'] } : {}), + config: config('target', generation, failure), + }) + const render = (id: string, failure?: Failure, generation = 1) => { + let text = `- insert: ${JSON.stringify([observer, witness(generation), target(id, failure, generation)])}` + if (failure === 'config expression') text += `\n- id: ${id}\n config: !!js "(() => { throw new Error('matrix config expression') })()"\n` + if (failure === 'disabled expression') text += `\n- id: ${id}\n disabled: !!js "(() => { throw new Error('matrix disabled expression') })()"\n` + return text + '\n' + } + writeFileSync(patch, JSON.stringify([{ insert: [observer, witness(0)] }]) + '\n') + return { root, home, events, diagnostics, serverUrl, states, observer, stop, patch, watcher, render, url, config, witness, target } +} + +function start(f: ReturnType, extra: string[] = []) { + const child = execa(process.execPath, [bin, '--profile', 'web', '--patch', f.watcher, ...extra, '--no-open', '--port', '0'], { + cwd: f.root, + env: { ...process.env, DSH_HOME: f.home, DSH_AGENTS_HOME: join(f.root, '.agents'), DSH_TELEMETRY_DISABLED: '1', DEEPSEEK_API_KEY: 'keyless-matrix-no-call', NODE_NO_WARNINGS: '1' }, + input: '', reject: false, timeout: 110_000, killSignal: 'SIGKILL', + }) + let stdout = '' + let stderr = '' + child.stdout?.setEncoding('utf8').on('data', (text: string) => { stdout += text }) + child.stderr?.setEncoding('utf8').on('data', (text: string) => { stderr += text }) + let exited = false + void child.then(() => { exited = true }) + async function wait(predicate: () => boolean) { + try { + await expect.poll(() => { + if (exited) throw new Error('Web process exited') + return predicate() + }, { timeout: 45_000 }).toBe(true) + } catch (cause) { throw new Error(`Web condition failed\n${stdout}\n${stderr}\n${readFileSync(f.diagnostics, 'utf8')}\n${readFileSync(f.events, 'utf8')}`, { cause }) } + } + async function serves(currentServer = false) { + await wait(() => /dsh web: http:\/\//u.test(stdout)) + const url = currentServer ? readFileSync(f.serverUrl, 'utf8') : /dsh web: (http:\/\/[^\s]+)/u.exec(stdout)?.[1] + if (!url) throw new Error('Missing Web URL') + const auth = await fetch(url, { redirect: 'manual', signal: AbortSignal.timeout(10_000) }) + const cookie = auth.headers.get('set-cookie')?.split(';', 1)[0] + if (!cookie) throw new Error('Missing Web authentication cookie') + const response = await fetch(new URL('/', url), { headers: { cookie }, signal: AbortSignal.timeout(10_000) }) + expect(response.status).toBe(200) + const html = await response.text() + expect(html).toContain('__DSH_BOOT__') + const bundlePath = /