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:
1 parent
e13c1828a4
commit
046834bcb6
35 files changed
+3812
-1963
No files matched your search
@@ -284,6 +284,11 @@ impl ExecutionController {
|
||||
let started = Instant::now();
|
||||
let outcome = self.run_core(&job, &plan);
|
||||
let cancel_requested = job.cancel.load(Ordering::SeqCst);
|
||||
eprintln!(
|
||||
"JOB_DEBUG id={} run_core elapsed={:?} cancel={cancel_requested}",
|
||||
job.run_id,
|
||||
started.elapsed()
|
||||
);
|
||||
let terminal = self.build_terminal(&plan, &static_doc, started, outcome, cancel_requested);
|
||||
let Ok(mut inner) = job.inner.lock() else {
|
||||
return;
|
||||
@@ -308,6 +313,12 @@ impl ExecutionController {
|
||||
);
|
||||
}
|
||||
}
|
||||
eprintln!(
|
||||
"JOB_DEBUG id={} terminal state={:?} total={:?}",
|
||||
job.run_id,
|
||||
state,
|
||||
started.elapsed()
|
||||
);
|
||||
inner.terminal_at = Some(Instant::now());
|
||||
drop(inner);
|
||||
|
||||
@@ -548,6 +559,7 @@ impl ExecutionController {
|
||||
detail: "job lock poisoned".to_string(),
|
||||
})?;
|
||||
let state_now = inner.log.last_state();
|
||||
eprintln!("CANCEL_DEBUG id={} last_state={state_now:?}", job.run_id);
|
||||
if state_now.is_terminal() {
|
||||
return Ok(state_now);
|
||||
}
|
||||
@@ -902,10 +914,27 @@ fn build_trace_summary(
|
||||
}
|
||||
};
|
||||
let projection = verified.projection;
|
||||
let statements = static_doc.verified.projection.all_statements();
|
||||
let events = projection
|
||||
.events
|
||||
.iter()
|
||||
.map(|event| {
|
||||
let source_id = if stale {
|
||||
None
|
||||
} else {
|
||||
event.anchor_span.and_then(|span| {
|
||||
statements
|
||||
.iter()
|
||||
.find(|(_, statement)| statement.span == span)
|
||||
.map(|(_, statement)| {
|
||||
crate::protocol::analysis_v2::source_id(
|
||||
&static_doc.verified.projection.module_id,
|
||||
span,
|
||||
&format!("statement-{}", statement.kind.data_value()),
|
||||
)
|
||||
})
|
||||
})
|
||||
};
|
||||
serde_json::json!({
|
||||
"seq": event.seq,
|
||||
"kind": event.kind_label(),
|
||||
@@ -916,6 +945,7 @@ fn build_trace_summary(
|
||||
event.anchor_span.map(|span| serde_json::json!({"start": span.start, "end": span.end}))
|
||||
.unwrap_or(serde_json::Value::Null)
|
||||
},
|
||||
"source_id": source_id,
|
||||
"detail": event.detail,
|
||||
"operation": event.operation,
|
||||
"duration_micros": event.duration_micros,
|
||||
|
||||
Reference in new issue
Block a user