Skip to content

Commit 4095d41

Browse files
committed
feat(cli): add sparkctl context pipeline
1 parent 6867649 commit 4095d41

10 files changed

Lines changed: 309 additions & 1 deletion
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Phase 4D sparkctl context-all Planning Handbook
2+
3+
## 1. Objective
4+
Define the implementation blueprint for the `sparkctl context-all` subcommand. This subcommand orchestrates the complete contextual lifecycle by running the internal tool sequence: `context-build`, `context-render`, and `context-validate` in order.
5+
6+
## 2. Strict Scope
7+
- **Command:** `sparkctl context-all`
8+
- **Exact Internal Command Sequence:**
9+
1. `context-build`
10+
2. `context-render`
11+
3. `context-validate`
12+
- **Default Input/Output Paths:**
13+
- Input Package: `../artifacts/spark/extraction.spkg`
14+
- Input Schema: `../schemas/genehmigung_v1.json`
15+
- Output Context JSON: `../artifacts/spark/context.json`
16+
- Output Rendered Context TXT: `../artifacts/spark/context_render.txt`
17+
- **Exit Code:** Exits with status `0` if all steps pass successfully, and a non-zero code if any step fails.
18+
- **Stop on Failure:** The orchestration must stop on the first failed step (i.e. if `context-build` fails, it must not execute `context-render`).
19+
20+
## 3. Forbidden Scope
21+
- **No Git Access:** The command must not run any git command or perform git operations.
22+
- **No Network Usage:** Work must occur 100% offline.
23+
- **No File Mutations Outside Declared Artifacts:** The command must update only `../artifacts/spark/context.json` and `../artifacts/spark/context_render.txt`.
24+
- **No Directory Escapes:** Do not scan folders outside the sandbox directory.
25+
- **No Compliance Claims:** No claims regarding EU AI Act or official SPARK schemas compatibility.
26+
- **No Raw Payload Dumps:** Ensure logs do not print original payload fields (applicant, recommendation, notes).
27+
28+
## 4. Execution & Reporting Rules
29+
- **Execution Directory:** The tool must execute local subcommands within the `agy7rust` workspace directory root path.
30+
- **Diagnostics Formatting:** Output must show a clean list of checked subcommands with status indicator tags (e.g. `[BUILD] PASS`, `[RENDER] PASS`, `[VALIDATE] PASS`).
31+
32+
## 5. Safety & Security Boundaries
33+
- Validation runs local crate subcommands only via direct execution or library orchestration.
34+
- Offline behavior was deterministic in the validated test scope.
35+
- Configured leak checks passed in the validated scope.
36+
- No blocking risks found in the validated scope.
37+
38+
## 6. Validation Checklist
39+
Before completion, verification must confirm:
40+
```bash
41+
cargo check
42+
cargo test
43+
sparkctl doctor
44+
sparkctl rust-validate
45+
sparkctl context-all
46+
```
47+
48+
## 7. Stop Conditions
49+
Stop implementation and return `blocked` if:
50+
- Command execution requires external registry updates or internet connections.
51+
- Validation checks require accessing remote credentials or secrets.
52+
53+
## 8. Return Format for Phase 4D Implementation
54+
```text
55+
PHASE: Phase 4D sparkctl context-all implementation
56+
STATUS: success | blocked
57+
COMMANDS_RUN:
58+
- ...
59+
FILES_CHANGED:
60+
- ...
61+
CONTEXT_ALL_OUTPUT:
62+
- ...
63+
VALIDATION:
64+
- ...
65+
RISKS:
66+
- ...
67+
NEXT:
68+
- Phase 4E implementation or audit only after approval
69+
```
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Phase 4D Snapshot Report — sparkctl context-all audit
2+
3+
## 1. Sandbox Root & Scope
4+
- **Phase Name:** Phase 4D sparkctl context-all audit and snapshot
5+
- **Sandbox Root:** `C:\Users\contr\sandbox_workspace\Antigravity-Comptextv7-unified`
6+
7+
## 2. Files Inspected
8+
The following modified and created files were audited for structural correctness:
9+
- [agy7rust/src/bin/sparkctl.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/bin/sparkctl.rs) (CLI entrypoint modified to register the `context-all` subcommand)
10+
- [agy7rust/src/commands/mod.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/commands/mod.rs) (Modified to add schema Option argument to context-validate)
11+
- [agy7rust/src/main.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/main.rs) (Modified to load, verify, and validate context against the provided schema definition)
12+
- [agy7rust/src/sparkctl/mod.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/sparkctl/mod.rs) (Modified to export `context_all` module)
13+
- [agy7rust/src/sparkctl/context_all.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/sparkctl/context_all.rs) (Created subcommand runner implementation)
14+
- [agy7rust/tests/spark_roundtrip.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/tests/spark_roundtrip.rs) (Modified to append `test_sparkctl_context_all_execution` integration test)
15+
- [agy7rust/PHASE4D_STATUS.md](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/PHASE4D_STATUS.md) (Created/updated status overview)
16+
- [agy7rust/PHASE4D_FIX_STATUS.md](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/PHASE4D_FIX_STATUS.md) (Created fix overview detailing schema parameter support)
17+
- [PHASE4D_SPARKCTL_CONTEXT_ALL_HANDBOOK.md](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/PHASE4D_SPARKCTL_CONTEXT_ALL_HANDBOOK.md) (Created planning handbook)
18+
19+
## 3. CLI Command Surface
20+
- **Implemented Commands:**
21+
- `sparkctl doctor`
22+
- `sparkctl rust-validate`
23+
- `sparkctl context-all`
24+
- **Other Phase 4 Commands Status:**
25+
- `spark-demo` (Not implemented)
26+
- `handoff-check` (Not implemented)
27+
28+
## 4. Context-All Command Sequence
29+
The orchestration runner executes the following steps in order:
30+
1. `cargo run -- context-build -i ../artifacts/spark/extraction.spkg -s ../schemas/genehmigung_v1.json -o ../artifacts/spark/context.json`
31+
2. `cargo run -- context-render -i ../artifacts/spark/context.json -o ../artifacts/spark/context_render.txt`
32+
3. `cargo run -- context-validate -i ../artifacts/spark/context.json -s ../schemas/genehmigung_v1.json`
33+
34+
## 5. Schema Argument Confirmation
35+
- **Verification Status:** Passed. The main CLI's `context-validate` command accepts the `-s/--schema` argument. When executed, it successfully loads the schema file and performs a real validation check to verify that context metadata (schema name, required field paths) matches the schema definition, printing `OK: schema verification passed`.
36+
37+
## 6. Safety & Security Boundaries
38+
- **No Git / Remote Actions:** `context-all` does not execute git commands, add remotes, or perform git commits/pushes.
39+
- **No Network Activity:** The subcommand executes orchestration checks entirely offline.
40+
- **Strict Directory Bounds:** Check executions are restricted to the local workspace; no parent/sibling directory scans are initiated.
41+
- **First-Failure Stop:** The command stops execution upon encountering the first failed validation command and returns a non-zero exit code.
42+
- **Determinism:** Offline behavior was deterministic in the validated test scope.
43+
44+
## 7. Leak & Privacy Boundaries
45+
- Configured leak checks passed in the validated scope.
46+
- The `context-all` command restricts its operations to running local compilers and checkers. No raw extraction payloads, applicant strings, decision recommendations, or extraction notes are printed or exposed.
47+
48+
## 8. Test Suite Status
49+
- **Current Total Integration Tests:** 30 tests.
50+
- **New Test Cases Added:** `test_sparkctl_context_all_execution` verifies that the `context-all` binary can be compiled and successfully executed via cargo, running build, render, and validate (including the schema argument check) and exiting with status 0.
51+
52+
## 9. Artifact Update Status
53+
- The orchestration updates only `../artifacts/spark/context.json` and `../artifacts/spark/context_render.txt`. Contents are correctly updated and validated.
54+
55+
## 10. Execution Logs
56+
- `cargo fmt --all --check` -> OK (Success)
57+
- `cargo check` -> OK (Success)
58+
- `cargo test` -> OK (30 tests passed successfully)
59+
- `cargo clippy -- -D warnings` -> OK (Success)
60+
- `cargo run -- context-validate -i ../artifacts/spark/context.json -s ../schemas/genehmigung_v1.json` -> OK (OK: schema verification passed)
61+
- `cargo run --bin sparkctl -- doctor` -> OK (doctor result: PASS)
62+
- `cargo run --bin sparkctl -- rust-validate` -> OK (rust-validate result: PASS)
63+
- `cargo run --bin sparkctl -- context-all` -> OK (context-all result: PASS)
64+
65+
## 11. Risks
66+
- No blocking risks found in the validated scope.
67+
68+
## 12. Recommended Next Phase
69+
- Commit Phase 4D only after approval.

agy7rust/PHASE4D_FIX_STATUS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Phase 4D Fix Status Report — Schema Argument Support in context-validate
2+
3+
## 1. Scope Accomplished
4+
- Modified [src/commands/mod.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/commands/mod.rs) to add `schema: Option<String>` to `Commands::ContextValidate`.
5+
- Modified [src/main.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/main.rs) to match the new `schema` argument and execute a real, non-faked validation check comparing the context metadata (schema name, required field paths) with the loaded schema file definition if a schema path is provided.
6+
- Updated [src/sparkctl/context_all.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/sparkctl/context_all.rs) to pass `-s ../schemas/genehmigung_v1.json` to the subcommand execution.
7+
8+
## 2. Validation Status
9+
- Crate formatting check: Passed
10+
- Compilation checks: Passed
11+
- Crate tests: Passed (30/30 tests passed successfully)
12+
- Direct command verification: Running `cargo run --bin agy7rust -- context-validate -i ../artifacts/spark/context.json -s ../schemas/genehmigung_v1.json` completed with status 0, printing `OK: schema verification passed`.
13+
14+
## 3. Safety & Leak Boundaries
15+
- Offline behavior was deterministic in the validated test scope.
16+
- Configured leak checks passed in the validated scope.
17+
- No blocking risks found in the validated scope.

agy7rust/PHASE4D_STATUS.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Phase 4D Status Report — sparkctl context-all implementation
2+
3+
## 1. Scope Accomplished
4+
- Implemented `sparkctl context-all` subcommand in [src/sparkctl/context_all.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/sparkctl/context_all.rs) and registered it inside [src/sparkctl/mod.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/sparkctl/mod.rs) and [src/bin/sparkctl.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/src/bin/sparkctl.rs).
5+
- Added schema-argument (`-s`) support to the main `context-validate` subcommand and updated the execution path to validate context against the provided schema definition.
6+
- Updated `sparkctl context-all` command orchestration to pass `-s ../schemas/genehmigung_v1.json` to the validation tool.
7+
- Added `test_sparkctl_context_all_execution` integration test in [tests/spark_roundtrip.rs](file:///C:/Users/contr/sandbox_workspace/Antigravity-Comptextv7-unified/git_post_push_verification/repo/agy7rust/tests/spark_roundtrip.rs) to verify correct execution of the new subcommand.
8+
9+
## 2. Validation Status
10+
- Crate formatting check: Passed
11+
- Compilation checks: Passed
12+
- Crate tests: Passed (30/30 tests passed successfully)
13+
- Clippy warnings check: Passed
14+
15+
## 3. Safety & Leak Boundaries
16+
- Offline behavior was deterministic in the validated test scope.
17+
- Configured leak checks passed in the validated scope.
18+
- No blocking risks found in the validated scope.

agy7rust/src/bin/sparkctl.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ enum Commands {
1818
Doctor,
1919
#[command(about = "Run local Rust quality checks (fmt, check, test, clippy)")]
2020
RustValidate,
21+
#[command(about = "Run complete context lifecycle (build, render, validate)")]
22+
ContextAll,
2123
}
2224

2325
fn main() -> Result<()> {
@@ -30,6 +32,9 @@ fn main() -> Result<()> {
3032
Commands::RustValidate => {
3133
sparkctl::rust_validate::run_rust_validate()?;
3234
}
35+
Commands::ContextAll => {
36+
sparkctl::context_all::run_context_all()?;
37+
}
3338
}
3439

3540
Ok(())

agy7rust/src/commands/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,7 @@ pub enum Commands {
6868
ContextValidate {
6969
#[arg(short = 'i', long = "input")]
7070
input: String,
71+
#[arg(short = 's', long = "schema")]
72+
schema: Option<String>,
7173
},
7274
}

agy7rust/src/main.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,46 @@ fn main() -> anyhow::Result<()> {
3333
Commands::ContextRender { input, output } => {
3434
agy7rust::commands::context_render::run(&input, &output)?;
3535
}
36-
Commands::ContextValidate { input } => {
36+
Commands::ContextValidate { input, schema } => {
3737
agy7rust::commands::context_validate::run(&input)?;
38+
39+
if let Some(schema_path) = schema {
40+
let context_content = std::fs::read_to_string(&input)?;
41+
let context_json: serde_json::Value = serde_json::from_str(&context_content)?;
42+
43+
let schema_content = std::fs::read_to_string(&schema_path)?;
44+
let schema_json: serde_json::Value = serde_json::from_str(&schema_content)?;
45+
46+
// Verify schema name
47+
if let (Some(ctx_name), Some(sch_name)) =
48+
(context_json.get("schema_name"), schema_json.get("name"))
49+
{
50+
if ctx_name != sch_name {
51+
return Err(anyhow::anyhow!(
52+
"Schema name mismatch: context has '{}', schema has '{}'",
53+
ctx_name,
54+
sch_name
55+
));
56+
}
57+
}
58+
59+
// Verify required field paths match
60+
if let (Some(ctx_paths), Some(sch_paths)) = (
61+
context_json.get("required_field_paths"),
62+
schema_json.get("required_field_paths"),
63+
) {
64+
let mut ctx_paths_vec: Vec<String> = serde_json::from_value(ctx_paths.clone())?;
65+
let mut sch_paths_vec: Vec<String> = serde_json::from_value(sch_paths.clone())?;
66+
ctx_paths_vec.sort();
67+
sch_paths_vec.sort();
68+
if ctx_paths_vec != sch_paths_vec {
69+
return Err(anyhow::anyhow!(
70+
"Required field paths mismatch between context and schema"
71+
));
72+
}
73+
}
74+
println!("OK: schema verification passed");
75+
}
3876
}
3977
}
4078

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use anyhow::{anyhow, Result};
2+
use std::process::Command;
3+
4+
pub fn run_context_all() -> Result<()> {
5+
let steps = vec![
6+
(
7+
"cargo run -- context-build -i ../artifacts/spark/extraction.spkg -s ../schemas/genehmigung_v1.json -o ../artifacts/spark/context.json",
8+
vec![
9+
"run",
10+
"--bin",
11+
"agy7rust",
12+
"--",
13+
"context-build",
14+
"-i",
15+
"../artifacts/spark/extraction.spkg",
16+
"-s",
17+
"../schemas/genehmigung_v1.json",
18+
"-o",
19+
"../artifacts/spark/context.json",
20+
],
21+
),
22+
(
23+
"cargo run -- context-render -i ../artifacts/spark/context.json -o ../artifacts/spark/context_render.txt",
24+
vec![
25+
"run",
26+
"--bin",
27+
"agy7rust",
28+
"--",
29+
"context-render",
30+
"-i",
31+
"../artifacts/spark/context.json",
32+
"-o",
33+
"../artifacts/spark/context_render.txt",
34+
],
35+
),
36+
(
37+
"cargo run -- context-validate -i ../artifacts/spark/context.json -s ../schemas/genehmigung_v1.json",
38+
vec![
39+
"run",
40+
"--bin",
41+
"agy7rust",
42+
"--",
43+
"context-validate",
44+
"-i",
45+
"../artifacts/spark/context.json",
46+
"-s",
47+
"../schemas/genehmigung_v1.json",
48+
],
49+
),
50+
];
51+
52+
println!("=== sparkctl context-all ===");
53+
54+
for &(display_name, ref args) in &steps {
55+
println!(" - running: {}...", display_name);
56+
57+
let status = Command::new("cargo")
58+
.args(args)
59+
.status()
60+
.map_err(|e| anyhow!("Failed to execute '{}': {}", display_name, e))?;
61+
62+
if !status.success() {
63+
println!(
64+
" [FAIL] {} failed with exit status: {}",
65+
display_name, status
66+
);
67+
return Err(anyhow!("Check '{}' failed", display_name));
68+
} else {
69+
println!(" [PASS] {}", display_name);
70+
}
71+
}
72+
73+
println!("context-all result: PASS");
74+
Ok(())
75+
}

agy7rust/src/sparkctl/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
pub mod context_all;
12
pub mod doctor;
23
pub mod rust_validate;

agy7rust/tests/spark_roundtrip.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,3 +1152,17 @@ fn test_sparkctl_rust_validate_execution() {
11521152
assert!(stdout_str.contains("=== sparkctl rust-validate ==="));
11531153
assert!(stdout_str.contains("rust-validate result: PASS"));
11541154
}
1155+
1156+
#[test]
1157+
fn test_sparkctl_context_all_execution() {
1158+
use std::process::Command;
1159+
let output = Command::new("cargo")
1160+
.args(&["run", "--bin", "sparkctl", "--", "context-all"])
1161+
.output()
1162+
.expect("failed to execute cargo run");
1163+
1164+
assert!(output.status.success());
1165+
let stdout_str = String::from_utf8_lossy(&output.stdout);
1166+
assert!(stdout_str.contains("=== sparkctl context-all ==="));
1167+
assert!(stdout_str.contains("context-all result: PASS"));
1168+
}

0 commit comments

Comments
 (0)