Repository navigation
feat(workspace): S-1 response-file client + M-13 opt-in excerpt export - #293
Conversation
S-1: add POST /api/v2/review-queue/responses writing one immutable portable review response through the shared respond()/RespondOptions path for all four closed families (/1 review, /2 lifecycle, /3 authoring, /4 edit). Preserves loopback, exact-Host pin, project confinement, write-scoped capability and native no-replace publication. New CM-53 writeReviewResponse operation; v1 contract frozen. No new review-family wire contract. M-13: explicit opt-in bounded source excerpts for trace exports. CLI --include-source-excerpts and v2 ExportRequest.include_source_excerpts; the conservative IdsAndHashes default is retained and byte-identical (no excerpts field). Excerpts are trace-only, bounded (100 items, 500 chars), untrusted. Tests: S-1 round-trip + confinement/auth/no-replace refusals; M-13 default byte-identical vs opt-in excerpts. fmt/clippy clean; full suite green except the confirmed-flaky workflow::fake test (passes in isolation, untouched).
CodeRabbit PR #290: the S-1 dispatcher matched the private canonical key unconditionally, so a v2 launch admitted /api/v2/review-queue/responses against the OpenAPI contract but never reached write_response, while the frozen v1 namespace kept an unintended alias. Gate the route on ApiMajor::V2 and the exact /api/v2/review-queue/responses wire path, mirroring the other v2 mutation routes; transport admission (loopback, exact-Host pin, write-scoped capability) and the handler's confinement fences are unchanged. Add a dispatch-level test: v2 POST publishes and round-trips the response, v1 is refused not-found. Capability matrix doc: current API2.4 draft total 65 -> 66 with CM-53 writeReviewResponse (matches the OpenAPI count and contract tests).
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 40 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
4 open issues
object[\"...\"]on aserde_json::Mapwill panic if the key is missing. Sinceexcerptscan… · New This conditional appears to enforce that excerpts are only allowed for trace reports, but it… · New This eagerly re-splits the entiresourceintolines: Vec<&str>for every resolved trace entry,… · New Gatingrender()behind#[cfg(test)]makes this helper unavailable to non-test crate code and… · New
What changed in this PR
Adds an S-1 v2 API endpoint to write confined portable review response files via the shared respond() pipeline, and introduces M-13 opt-in bounded source excerpts for trace exports while keeping the default export byte-identical.
Changes:
- Add
POST /api/v2/review-queue/responses(writeReviewResponse) handler + dispatch + contract/docs updates. - Add opt-in
include_source_excerptsplumbing for trace exports, plus excerpt extraction/validation and CLI flag support. - Update API contract validation expectations and capability matrix to include the new operation.
| File | Description |
|---|---|
| tests/api_contract_validation.rs | Updates expected operation counts to include the new v2 operation. |
| src/workspace/reports.rs | Adds optional excerpts field, v1/v2 contract validation split, excerpt validation, and tests. |
| src/workspace/http_review.rs | Introduces S-1 response-file write handler + tests validating confinement, refusal behavior, and routing. |
| src/workspace/http.rs | Wires the new v2 route into dispatch. |
| src/workspace/domain.rs | Implements bounded trace source excerpt extraction (M-13). |
| src/workspace/actions.rs | Adds include_source_excerpts request handling and renders reports with optional excerpts. |
| src/cli/trace.rs | Adds --include-source-excerpts output formatting for trace CLI. |
| src/cli/mod.rs | Adds CLI flag plumbing for include_source_excerpts. |
| docs/api/forge-workspace-v2.openapi.yaml | Documents the new endpoint, error code, request flag, and report excerpts schema. |
| docs/api/capability-matrix-v2.md | Updates operation totals and adds CM-53 entry. |
| docs/api/capability-matrix-v2.json | Adds writeReviewResponse to the CI denominator list and declares CM-53. |
Review effort: Lite
| if let Some(excerpts) = &self.excerpts { | ||
| if self.kind != "trace" || excerpts.len() > 100 { | ||
| return Err(Error::invalid()); | ||
| } | ||
| for excerpt in excerpts { | ||
| let object = excerpt.as_object().ok_or_else(Error::invalid)?; | ||
| if object.len() != 5 | ||
| || object["element_id"].as_str().is_none_or(|s| s.is_empty() || s.len() > 200) | ||
| || object["source_file"].as_str().is_none_or(|s| s.is_empty() || s.len() > 512) | ||
| || object["source_line"].as_u64().is_none_or(|n| n == 0 || n > 1_000_000) | ||
| || object["text"].as_str().is_none_or(|s| s.len() > 500) | ||
| || object["truncated"].as_bool().is_none() | ||
| { | ||
| return Err(Error::invalid()); | ||
| } | ||
| } | ||
| } |
| { | ||
| "if": { | ||
| "properties": { | ||
| "excerpts": {} | ||
| }, | ||
| "required": [ | ||
| "excerpts" | ||
| ] | ||
| }, | ||
| "then": { | ||
| "properties": { | ||
| "report_kind": { | ||
| "const": "trace" | ||
| } | ||
| } | ||
| } | ||
| } |
| pub(crate) fn trace_excerpts(snapshot: &Snapshot) -> Result<Vec<serde_json::Value>> { | ||
| let mut excerpts = Vec::new(); | ||
| for item in snapshot.items.iter().filter(|item| { | ||
| matches!(item.registration.role, Role::OscalCatalogArtifact | Role::OscalComponentArtifact) | ||
| }) { | ||
| for entry in trace_entries(item)? { | ||
| let Some(trace) = entry.trace else { continue }; | ||
| let Some(source) = trace_source(snapshot, &trace) else { continue }; | ||
| let text = std::str::from_utf8(&source.captured.bytes).map_err(|_| invalid())?; | ||
| let lines: Vec<&str> = text.lines().collect(); | ||
| if !crate::trace::resolver::validate_line_reference(trace.source_line, lines.len()) { | ||
| continue; | ||
| } | ||
| let Some(line) = trace.source_line else { continue }; |
| Ok(pins) | ||
| } | ||
|
|
||
| #[cfg(test)] |



Re-opened from #290 (auto-closed when its stacked base feat/f12-f13-m10-adapters was deleted on #288 merge). Rebased onto current main; M-10 is already merged.
S-1: POST /api/v2/review-queue/responses (CM-53 writeReviewResponse) writes one immutable portable response through the shared respond() path for all four closed families. Security preserved (loopback, exact-Host, write-scoped capability, confinement, no-replace).
M-13: opt-in bounded source excerpts (forge trace --include-source-excerpts + v2 include_source_excerpts); conservative IdsAndHashes default byte-identical.
CodeRabbit findings remediated: v1/v2 route mismatch fixed (handler now reachable on the documented v2 path) + dispatch test; operation count 65->66.
Verification: 10 S-1/M-13 tests green; full suite green; fmt/clippy clean.