feat(PR-04): SSE execution loop, 7-route server and session security

- replace src/server.rs with src/server/{mod,routes,security,sse}.rs implementing
  exactly the RFC-0002 §6.2 routes: GET /, GET /file, GET /assets, GET
  /api/documents, POST /api/runs, GET /api/runs/{id}/events, POST
  /api/runs/{id}/cancel; old /api/health, /api/document, /api/run and
  /api/clear-run are gone (404)
- SSE writes the event-stream directly to the socket and flushes every frame and
  heartbeat (tiny_http's chunked writer would delay frames); Last-Event-ID
  replay or authoritative snapshot, 128-event ring, terminal close, heartbeat
  comments, at most two observers per run, no polling route
- per-session HttpOnly SameSite=Strict cookie + X-View-CSRF, exact same-origin
  Origin, loopback Host, Sec-Fetch-Site cross-site rejection, JSON-only 64 KiB
  run POSTs; cancel is an authenticated bodyless control POST
- reader.js: Analysis-driven function form with text-only command preview,
  pure/project mode + explicit fs grants with second confirmation, one POST then
  EventSource, cancel, live result/stdout/stderr/Trace panel and keyed source
  anchors (skipped when stale); no innerHTML of CLI data and no status polling
- render: hidden live run shell, generic explicit-run dialog, function call
  buttons carrying Analysis function ids/params, data-analysis-digest/document
  attributes; remove the old run-confirm dialog and run-page reload path
- add tests/security/ suite, rewrite HTTP/SSE integration tests, update browser
  suite for EventSource/dark theme/RFC width matrix (incl. 2048x1133)
- ADR-0009 + docs/evidence/PR-04 with real Chromium log/screenshots and a real
  frozen-CLI SSE run (285 Trace v2 events, CLI SHA unchanged)
- unit 63 + contract 41 + integration 40 + security 11 pass; clippy clean
This commit is contained in:
cflmy committed 2026-11-22 14:30:40 +08:00
1 parent e13c1828a4
commit 046834bcb6
35 files changed
+3812 -1963

No files matched your search

+6
View File
@@ -46,6 +46,8 @@ pub enum ViewError {
RunInvalid { detail: String },
/// The entry document has no resolvable `main`; View never substitutes one.
NoEntryFunction { detail: String },
/// A page/SSE/POST requires a valid local session cookie.
SessionRequired { detail: String },
/// Another explicit run is already active; View allows one at a time.
RunBusy { detail: String },
/// The same client request id was reused with a different payload.
@@ -85,6 +87,7 @@ impl ViewError {
ViewError::CoreTimeout { .. } => "view.core_timeout",
ViewError::RunInvalid { .. } => "view.run_invalid",
ViewError::NoEntryFunction { .. } => "view.no_entry_function",
ViewError::SessionRequired { .. } => "view.session_required",
ViewError::RunBusy { .. } => "view.run_busy",
ViewError::RunConflict { .. } => "view.run_conflict",
ViewError::RunNotFound { .. } => "view.run_not_found",
@@ -107,6 +110,7 @@ impl ViewError {
| ViewError::Unsupported { .. }
| ViewError::RunInvalid { .. }
| ViewError::NoEntryFunction { .. }
| ViewError::SessionRequired { .. }
| ViewError::RunBusy { .. }
| ViewError::RunConflict { .. }
| ViewError::RunNotFound { .. }
@@ -152,6 +156,7 @@ impl ViewError {
"view.core_timeout" => "冻结核心执行超时,已终止。",
"view.run_invalid" => "运行请求未通过校验(目标、参数、模式或授权不合法)。",
"view.no_entry_function" => "文档没有可调用的 main;请改选一个 H2 Exec 函数。",
"view.session_required" => "缺少或过期的本地会话;请先打开阅读页面。",
"view.run_busy" => "已有一次运行正在进行;本版本每个 View 服务只允许一个任务。",
"view.run_conflict" => "同一客户端请求 ID 携带了不同内容,拒绝执行。",
"view.run_not_found" => "运行任务不存在、已过期或不属于当前会话。",
@@ -204,6 +209,7 @@ impl ViewError {
| ViewError::CoreTimeout { detail }
| ViewError::RunInvalid { detail }
| ViewError::NoEntryFunction { detail }
| ViewError::SessionRequired { detail }
| ViewError::RunBusy { detail }
| ViewError::RunConflict { detail }
| ViewError::RunNotFound { detail }