Delete unowned executable surfaces
This commit is contained in:
parent
103e851059
commit
1d5a1f1793
51 changed files with 87 additions and 19339 deletions
|
|
@ -1,398 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-adoption-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Adoption Request Family Smoke\n\nThis repository proves branch-local Mind adoption requests.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed repo adoption request smoke body"],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
["switch", "-c", "epiphany/repo-adoption-request-family"],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-adoption-request-family";
|
||||
let target_path = ".epiphany/adoption-requests/repo-adoption-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-adoption-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-adoption-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-adoption-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask Mind to adopt or refuse a reviewable Objective Draft before Self schedules branch-local work.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-adoption-request-family/mind-review",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-adoption-request-family/refuse-or-adopt",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-adoption-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-adoption-request",
|
||||
"--model-ref",
|
||||
"repo-adoption-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.adoption_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_adoption_request.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"safe_action_family = \"repo.adoption_request\"",
|
||||
)?;
|
||||
require_text(&request_text, "[request]")?;
|
||||
require_text(&request_text, "status = \"awaiting-mind-review\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requested_decision = \"adopt-or-refuse-objective-draft\"",
|
||||
)?;
|
||||
require_text(&request_text, "mind_review_required = true")?;
|
||||
require_text(&request_text, "mind_state_commit_required = true")?;
|
||||
require_text(&request_text, "self_scheduling_after_mind_only = true")?;
|
||||
require_text(&request_text, "[decision_contract]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"allowed_verdicts = [\"adopted\", \"refused\", \"needs-more-consensus\"]",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requires_receipt = \"epiphany.mind.gateway_review\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requires_commit_receipt_if_adopted = \"epiphany.mind.state_commit_receipt\"",
|
||||
)?;
|
||||
require_text(&request_text, "does_not_modify_state = true")?;
|
||||
require_text(&request_text, "objective_draft_required = true")?;
|
||||
require_text(&request_text, "consensus_brief_required = true")?;
|
||||
require_text(&request_text, "objective_adoption_authorized = false")?;
|
||||
require_text(&request_text, "state_commit_authorized = false")?;
|
||||
require_text(&request_text, "self_scheduling_authorized = false")?;
|
||||
require_text(&request_text, "hands_action_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_work_adoption_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingMindReview": true,
|
||||
"doesNotModifyState": true,
|
||||
"stateCommitAuthorized": false,
|
||||
"selfSchedulingAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected adoption request text to contain {needle:?}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,533 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Child;
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
const DEFAULT_MODEL_RUNTIME_BIN: &str = "epiphany-model-runtime";
|
||||
const DEFAULT_TIMEOUT_SECONDS: u64 = 900;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let summary = run(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&summary)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
repo: PathBuf,
|
||||
baseline: PathBuf,
|
||||
artifact_dir: PathBuf,
|
||||
init_store: PathBuf,
|
||||
agent_store: PathBuf,
|
||||
heartbeat_store: PathBuf,
|
||||
runtime_store: PathBuf,
|
||||
model_runtime_bin: String,
|
||||
model_provider: String,
|
||||
executor: String,
|
||||
mode: String,
|
||||
model: Option<String>,
|
||||
timeout_seconds: u64,
|
||||
auto_accept: bool,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let root = env::current_dir().context("failed to resolve current dir")?;
|
||||
let mut args = env::args().skip(1);
|
||||
let mut parsed = Args {
|
||||
repo: root.clone(),
|
||||
baseline: root
|
||||
.join(".epiphany-imports")
|
||||
.join("repo-personality-terrain")
|
||||
.join("baseline.msgpack"),
|
||||
artifact_dir: root.join(".epiphany-birth-runner"),
|
||||
init_store: root.join("state").join("repo-initialization.msgpack"),
|
||||
agent_store: root.join("state").join("agents.msgpack"),
|
||||
heartbeat_store: root.join("state").join("agent-heartbeats.msgpack"),
|
||||
runtime_store: root.join("state").join("runtime-spine.msgpack"),
|
||||
model_runtime_bin: DEFAULT_MODEL_RUNTIME_BIN.to_string(),
|
||||
model_provider: "openai-codex".to_string(),
|
||||
executor: "model-runtime".to_string(),
|
||||
mode: "plan".to_string(),
|
||||
model: None,
|
||||
timeout_seconds: DEFAULT_TIMEOUT_SECONDS,
|
||||
auto_accept: false,
|
||||
};
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--repo" => parsed.repo = take_path(&mut args, "--repo")?,
|
||||
"--baseline" => parsed.baseline = take_path(&mut args, "--baseline")?,
|
||||
"--artifact-dir" => parsed.artifact_dir = take_path(&mut args, "--artifact-dir")?,
|
||||
"--init-store" => parsed.init_store = take_path(&mut args, "--init-store")?,
|
||||
"--agent-store" => parsed.agent_store = take_path(&mut args, "--agent-store")?,
|
||||
"--heartbeat-store" => {
|
||||
parsed.heartbeat_store = take_path(&mut args, "--heartbeat-store")?;
|
||||
}
|
||||
"--runtime-store" => {
|
||||
parsed.runtime_store = take_path(&mut args, "--runtime-store")?
|
||||
}
|
||||
"--model-runtime-bin" => {
|
||||
parsed.model_runtime_bin = take_string(&mut args, "--model-runtime-bin")?;
|
||||
}
|
||||
"--openai-runtime-bin" => {
|
||||
parsed.model_runtime_bin = take_string(&mut args, "--openai-runtime-bin")?;
|
||||
}
|
||||
"--model-provider" => {
|
||||
parsed.model_provider = take_string(&mut args, "--model-provider")?;
|
||||
}
|
||||
"--executor" => parsed.executor = take_string(&mut args, "--executor")?,
|
||||
"--mode" => parsed.mode = take_string(&mut args, "--mode")?,
|
||||
"--model" => parsed.model = Some(take_string(&mut args, "--model")?),
|
||||
"--timeout-seconds" => {
|
||||
parsed.timeout_seconds =
|
||||
take_string(&mut args, "--timeout-seconds")?.parse()?;
|
||||
}
|
||||
"--auto-accept" => parsed.auto_accept = true,
|
||||
other => return Err(anyhow!("unknown argument {other:?}")),
|
||||
}
|
||||
}
|
||||
if !matches!(parsed.mode.as_str(), "plan" | "run") {
|
||||
return Err(anyhow!("--mode must be plan or run"));
|
||||
}
|
||||
if parsed.executor == "openai-runtime" {
|
||||
parsed.executor = "model-runtime".to_string();
|
||||
}
|
||||
if parsed.executor != "model-runtime" {
|
||||
return Err(anyhow!(
|
||||
"--executor must be model-runtime; Codex CLI execution is not an Epiphany agent prompt path"
|
||||
));
|
||||
}
|
||||
Ok(parsed)
|
||||
}
|
||||
}
|
||||
|
||||
fn run(args: Args) -> Result<Value> {
|
||||
fs::create_dir_all(&args.artifact_dir)
|
||||
.with_context(|| format!("failed to create {}", args.artifact_dir.display()))?;
|
||||
let startup_dir = args.artifact_dir.join("startup");
|
||||
fs::create_dir_all(&startup_dir)?;
|
||||
let startup = run_repo_personality_json(&[
|
||||
"startup".to_string(),
|
||||
"--repo".to_string(),
|
||||
args.repo.display().to_string(),
|
||||
"--baseline".to_string(),
|
||||
args.baseline.display().to_string(),
|
||||
"--artifact-dir".to_string(),
|
||||
startup_dir.display().to_string(),
|
||||
"--init-store".to_string(),
|
||||
args.init_store.display().to_string(),
|
||||
])?;
|
||||
let packets = startup["generatedPackets"]
|
||||
.as_array()
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
let mut executions = Vec::new();
|
||||
for packet in packets {
|
||||
let kind = packet["kind"].as_str().unwrap_or("unknown");
|
||||
let packet_path = path_from_value(&packet["packetPath"])?;
|
||||
let execution_dir = args.artifact_dir.join(sanitize(kind));
|
||||
fs::create_dir_all(&execution_dir)?;
|
||||
let packet_value = read_json(&packet_path)?;
|
||||
let prompt_path = execution_dir.join("prompt.md");
|
||||
let schema_path = execution_dir.join("output-schema.json");
|
||||
let result_path = execution_dir.join("result.json");
|
||||
let request_path = execution_dir.join("model-request.json");
|
||||
let runtime_summary_path = execution_dir.join("model-runtime-summary.json");
|
||||
let stdout_path = execution_dir.join("executor.stdout.log");
|
||||
let stderr_path = execution_dir.join("executor.stderr.log");
|
||||
let prompt = render_specialist_prompt(kind, &packet_value)?;
|
||||
let schema = output_schema_for_kind(kind, &packet_value)?;
|
||||
write_text(&prompt_path, &prompt)?;
|
||||
write_json(&schema_path, &schema)?;
|
||||
let mut execution = json!({
|
||||
"kind": kind,
|
||||
"birthOnly": true,
|
||||
"executionOwner": "repo-initialization-startup-runner",
|
||||
"heartbeatParticipant": Value::Null,
|
||||
"packetPath": packet_path,
|
||||
"promptPath": prompt_path,
|
||||
"schemaPath": schema_path,
|
||||
"resultPath": result_path,
|
||||
"requestPath": request_path,
|
||||
"runtimeSummaryPath": runtime_summary_path,
|
||||
"stdoutPath": stdout_path,
|
||||
"stderrPath": stderr_path,
|
||||
"executor": args.executor.clone(),
|
||||
"modelRuntimeBin": args.model_runtime_bin.clone(),
|
||||
"modelProvider": args.model_provider.clone(),
|
||||
"status": "planned",
|
||||
"acceptCommand": accept_command(kind, &args, &packet_path, &result_path),
|
||||
});
|
||||
if args.mode == "run" {
|
||||
let run_result = run_openai_runtime_specialist(
|
||||
&args,
|
||||
kind,
|
||||
&prompt,
|
||||
&schema_path,
|
||||
&request_path,
|
||||
&result_path,
|
||||
&runtime_summary_path,
|
||||
&stdout_path,
|
||||
&stderr_path,
|
||||
)?;
|
||||
execution["status"] = run_result["status"].clone();
|
||||
execution["exitCode"] = run_result["exitCode"].clone();
|
||||
execution["timedOut"] = run_result["timedOut"].clone();
|
||||
if result_path.exists() {
|
||||
execution["result"] = read_json(&result_path).unwrap_or_else(|err| {
|
||||
json!({
|
||||
"status": "invalid-json",
|
||||
"error": err.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
if args.auto_accept && execution["status"] == "completed" {
|
||||
execution["acceptance"] = run_repo_personality_json(&accept_args(
|
||||
kind,
|
||||
&args,
|
||||
&packet_path,
|
||||
&result_path,
|
||||
))?;
|
||||
}
|
||||
}
|
||||
executions.push(execution);
|
||||
}
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_birth_runner.v0",
|
||||
"createdAt": Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
|
||||
"mode": args.mode,
|
||||
"repo": args.repo,
|
||||
"baseline": args.baseline,
|
||||
"artifactDir": args.artifact_dir,
|
||||
"initStore": args.init_store,
|
||||
"agentStore": args.agent_store,
|
||||
"heartbeatStore": args.heartbeat_store,
|
||||
"runtimeStore": args.runtime_store,
|
||||
"executor": args.executor,
|
||||
"modelRuntimeBin": args.model_runtime_bin,
|
||||
"modelProvider": args.model_provider,
|
||||
"startup": startup,
|
||||
"executions": executions,
|
||||
"requiresReview": !args.auto_accept,
|
||||
"nextSafeMove": if executions.is_empty() {
|
||||
"Birth initialization records are present; continue startup."
|
||||
} else if args.mode == "plan" {
|
||||
"Review planned startup-only birth executions, then rerun with --mode run."
|
||||
} else if args.auto_accept {
|
||||
"Review auto-accepted smoke output and continue startup."
|
||||
} else {
|
||||
"Review result.json for each birth specialist, then run the shown accept-init command."
|
||||
}
|
||||
});
|
||||
write_json(
|
||||
&args.artifact_dir.join("birth-runner-summary.json"),
|
||||
&summary,
|
||||
)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn run_openai_runtime_specialist(
|
||||
args: &Args,
|
||||
kind: &str,
|
||||
prompt: &str,
|
||||
schema_path: &Path,
|
||||
request_path: &Path,
|
||||
result_path: &Path,
|
||||
runtime_summary_path: &Path,
|
||||
stdout_path: &Path,
|
||||
stderr_path: &Path,
|
||||
) -> Result<Value> {
|
||||
let schema_text = fs::read_to_string(schema_path)
|
||||
.with_context(|| format!("failed to read {}", schema_path.display()))?;
|
||||
let model = args.model.clone().unwrap_or_else(|| "gpt-5.4".to_string());
|
||||
let request_id = format!(
|
||||
"repo-birth-{}-{}",
|
||||
sanitize(kind),
|
||||
Utc::now().timestamp_millis()
|
||||
);
|
||||
let request = json!({
|
||||
"schema_id": "epiphany.model_request.v0",
|
||||
"request_id": request_id,
|
||||
"conversation_id": format!("repo-birth-{}", sanitize(kind)),
|
||||
"provider": args.model_provider.clone(),
|
||||
"model": model,
|
||||
"instructions": format!(
|
||||
"{prompt}\n\nReturn only a single JSON object matching this output schema. No Markdown, no commentary.\n\n```json\n{schema_text}\n```"
|
||||
),
|
||||
"input": [
|
||||
{
|
||||
"UserText": {
|
||||
"text": "Execute this startup-only Epiphany birth distiller packet and return the reviewable JSON result."
|
||||
}
|
||||
}
|
||||
],
|
||||
"reasoning_effort": Value::Null,
|
||||
"reasoning_summary": Value::Null,
|
||||
"service_tier": Value::Null,
|
||||
"output_contract_id": format!("repo-birth-{kind}")
|
||||
});
|
||||
write_json(request_path, &request)?;
|
||||
|
||||
let mut command = Command::new(&args.model_runtime_bin);
|
||||
command
|
||||
.arg("model-turn")
|
||||
.arg("--provider")
|
||||
.arg(&args.model_provider)
|
||||
.arg("--store")
|
||||
.arg(&args.runtime_store)
|
||||
.arg("--request")
|
||||
.arg(request_path)
|
||||
.arg("--objective")
|
||||
.arg(format!("Run startup-only repo birth specialist {kind}"))
|
||||
.arg("--default-model")
|
||||
.arg(&model)
|
||||
.arg("--output-last-message")
|
||||
.arg(result_path)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
let child = command
|
||||
.spawn()
|
||||
.context("failed to spawn model runtime model-turn")?;
|
||||
wait_for_child(
|
||||
child,
|
||||
args.timeout_seconds,
|
||||
stdout_path,
|
||||
stderr_path,
|
||||
Some(runtime_summary_path),
|
||||
)
|
||||
}
|
||||
|
||||
fn wait_for_child(
|
||||
mut child: Child,
|
||||
timeout_seconds: u64,
|
||||
stdout_path: &Path,
|
||||
stderr_path: &Path,
|
||||
stdout_json_copy_path: Option<&Path>,
|
||||
) -> Result<Value> {
|
||||
let deadline = Instant::now() + Duration::from_secs(timeout_seconds);
|
||||
loop {
|
||||
if let Some(status) = child.try_wait()? {
|
||||
let output = child.wait_with_output()?;
|
||||
write_bytes(stdout_path, &output.stdout)?;
|
||||
write_bytes(stderr_path, &output.stderr)?;
|
||||
if let Some(path) = stdout_json_copy_path {
|
||||
write_bytes(path, &output.stdout)?;
|
||||
}
|
||||
return Ok(json!({
|
||||
"status": if status.success() { "completed" } else { "failed" },
|
||||
"exitCode": status.code(),
|
||||
"timedOut": false,
|
||||
}));
|
||||
}
|
||||
if Instant::now() >= deadline {
|
||||
let _ = child.kill();
|
||||
let output = child.wait_with_output()?;
|
||||
write_bytes(stdout_path, &output.stdout)?;
|
||||
write_bytes(stderr_path, &output.stderr)?;
|
||||
if let Some(path) = stdout_json_copy_path {
|
||||
write_bytes(path, &output.stdout)?;
|
||||
}
|
||||
return Ok(json!({
|
||||
"status": "timeout",
|
||||
"exitCode": Value::Null,
|
||||
"timedOut": true,
|
||||
}));
|
||||
}
|
||||
thread::sleep(Duration::from_millis(250));
|
||||
}
|
||||
}
|
||||
|
||||
fn render_specialist_prompt(kind: &str, packet: &Value) -> Result<String> {
|
||||
Ok(format!(
|
||||
"{}\n\n# Startup-Only Birth Packet\n\nYou are executing exactly one repo initialization birth specialist packet. Do not edit files. Do not mutate state. Return only JSON that matches the provided schema. The coordinator/Self will review and decide whether to accept the result.\n\n```json\n{}\n```\n",
|
||||
packet["prompt"].as_str().unwrap_or(match kind {
|
||||
"repo-trajectory" => "Act as the Epiphany Repo Trajectory Distiller.",
|
||||
"repo-personality" => "Act as the Epiphany Repo Personality Distiller.",
|
||||
"repo-memory" => "Act as the Epiphany Repo Memory Distiller.",
|
||||
_ => "Act as a startup-only Epiphany birth specialist.",
|
||||
}),
|
||||
serde_json::to_string_pretty(packet)?
|
||||
))
|
||||
}
|
||||
|
||||
fn output_schema_for_kind(kind: &str, packet: &Value) -> Result<Value> {
|
||||
let expected = packet.get("expectedOutput").cloned().unwrap_or(Value::Null);
|
||||
let schema = match kind {
|
||||
"repo-trajectory" => json!({
|
||||
"type": "object",
|
||||
"required": ["verdict", "summary", "confidence", "selfImage", "trajectoryNarrative", "implicitGoals", "antiGoals", "roleBiases", "selfPatchCandidates", "initializationRecord", "doNotMutate", "nextSafeMove"],
|
||||
"properties": {
|
||||
"verdict": {"type": "string", "enum": ["ready-for-review", "needs-more-history", "reject"]},
|
||||
"summary": {"type": "string"},
|
||||
"confidence": {"type": "number"},
|
||||
"selfImage": {"type": "string"},
|
||||
"trajectoryNarrative": {"type": "string"},
|
||||
"implicitGoals": {"type": "array", "items": {"type": "string"}},
|
||||
"antiGoals": {"type": "array", "items": {"type": "string"}},
|
||||
"roleBiases": {"type": "array", "items": {"type": "object"}},
|
||||
"selfPatchCandidates": {"type": "array", "items": {"type": "object"}},
|
||||
"initializationRecord": {"type": "object"},
|
||||
"doNotMutate": {"type": "array", "items": {"type": "string"}},
|
||||
"nextSafeMove": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": true,
|
||||
"xEpiphanyExpectedOutput": expected,
|
||||
}),
|
||||
"repo-personality" => json!({
|
||||
"type": "object",
|
||||
"required": ["verdict", "summary", "confidence", "roleQuirks", "selfPatchCandidates", "initializationRecord", "doNotMutate", "nextSafeMove"],
|
||||
"properties": {
|
||||
"verdict": {"type": "string", "enum": ["ready-for-review", "needs-more-terrain", "reject"]},
|
||||
"summary": {"type": "string"},
|
||||
"confidence": {"type": "number"},
|
||||
"roleQuirks": {"type": "array", "items": {"type": "object"}},
|
||||
"selfPatchCandidates": {"type": "array", "items": {"type": "object"}},
|
||||
"initializationRecord": {"type": "object"},
|
||||
"doNotMutate": {"type": "array", "items": {"type": "string"}},
|
||||
"nextSafeMove": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": true,
|
||||
"xEpiphanyExpectedOutput": expected,
|
||||
}),
|
||||
"repo-memory" => json!({
|
||||
"type": "object",
|
||||
"required": ["verdict", "summary", "confidence", "roleMemoryPatches", "initializationRecord", "doNotMutate", "nextSafeMove"],
|
||||
"properties": {
|
||||
"verdict": {"type": "string", "enum": ["ready-for-review", "needs-more-terrain", "reject"]},
|
||||
"summary": {"type": "string"},
|
||||
"confidence": {"type": "number"},
|
||||
"roleMemoryPatches": {"type": "array", "items": {"type": "object"}},
|
||||
"globalMemoryCandidates": {"type": "array", "items": {"type": "object"}},
|
||||
"initializationRecord": {"type": "object"},
|
||||
"doNotMutate": {"type": "array", "items": {"type": "string"}},
|
||||
"nextSafeMove": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": true,
|
||||
"xEpiphanyExpectedOutput": expected,
|
||||
}),
|
||||
other => return Err(anyhow!("unsupported birth specialist kind {other:?}")),
|
||||
};
|
||||
Ok(schema)
|
||||
}
|
||||
|
||||
fn accept_command(kind: &str, args: &Args, packet_path: &Path, result_path: &Path) -> Vec<String> {
|
||||
accept_args(kind, args, packet_path, result_path)
|
||||
}
|
||||
|
||||
fn accept_args(kind: &str, args: &Args, packet_path: &Path, result_path: &Path) -> Vec<String> {
|
||||
let mut out = vec![
|
||||
"accept-init".to_string(),
|
||||
"--init-store".to_string(),
|
||||
args.init_store.display().to_string(),
|
||||
"--packet".to_string(),
|
||||
packet_path.display().to_string(),
|
||||
"--kind".to_string(),
|
||||
kind.to_string(),
|
||||
"--accepted-by".to_string(),
|
||||
"Self".to_string(),
|
||||
"--summary".to_string(),
|
||||
format!("Accepted {kind} birth specialist result after review."),
|
||||
"--result".to_string(),
|
||||
result_path.display().to_string(),
|
||||
"--agent-store".to_string(),
|
||||
args.agent_store.display().to_string(),
|
||||
"--apply-self-patches".to_string(),
|
||||
"true".to_string(),
|
||||
];
|
||||
if kind == "repo-personality" {
|
||||
out.extend([
|
||||
"--heartbeat-store".to_string(),
|
||||
args.heartbeat_store.display().to_string(),
|
||||
"--apply-heartbeat-seeds".to_string(),
|
||||
"true".to_string(),
|
||||
]);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn run_repo_personality_json(args: &[String]) -> Result<Value> {
|
||||
let exe = native_exe("epiphany-repo-personality");
|
||||
let output = Command::new(&exe)
|
||||
.args(args)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run {}", exe.display()))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"epiphany-repo-personality failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout)
|
||||
.with_context(|| format!("epiphany-repo-personality returned invalid JSON"))
|
||||
}
|
||||
|
||||
fn native_exe(name: &str) -> PathBuf {
|
||||
let target_dir = env::var_os("CARGO_TARGET_DIR")
|
||||
.unwrap_or_else(|| r"C:\Users\Meta\.cargo-target-codex".into());
|
||||
PathBuf::from(target_dir)
|
||||
.join("debug")
|
||||
.join(format!("{name}{}", env::consts::EXE_SUFFIX))
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let raw =
|
||||
fs::read_to_string(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_str(&raw).with_context(|| format!("failed to decode {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_text(path: &Path, value: &str) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
fs::write(path, value).with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_bytes(path: &Path, value: &[u8]) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
fs::write(path, value).with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn path_from_value(value: &Value) -> Result<PathBuf> {
|
||||
value
|
||||
.as_str()
|
||||
.map(PathBuf::from)
|
||||
.ok_or_else(|| anyhow!("expected path string, got {value}"))
|
||||
}
|
||||
|
||||
fn sanitize(value: &str) -> String {
|
||||
value
|
||||
.chars()
|
||||
.map(|ch| if ch.is_ascii_alphanumeric() { ch } else { '-' })
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn take_string(args: &mut impl Iterator<Item = String>, name: &str) -> Result<String> {
|
||||
args.next()
|
||||
.ok_or_else(|| anyhow!("{name} requires a value"))
|
||||
}
|
||||
|
||||
fn take_path(args: &mut impl Iterator<Item = String>, name: &str) -> Result<PathBuf> {
|
||||
Ok(PathBuf::from(take_string(args, name)?))
|
||||
}
|
||||
|
|
@ -1,413 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-closure-source-grounding-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Closure Source Grounding Smoke\n\nThis repository proves Soul can require verification output to cite changed paths.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed closure source grounding smoke"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["switch", "-c", "epiphany/closure-source-grounding"], &repo)?;
|
||||
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"closure-source-grounding-smoke",
|
||||
"--topic",
|
||||
"closure-source-grounding",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"closure-source-grounding-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
|
||||
let good = drive_item(
|
||||
&manifest,
|
||||
&root,
|
||||
&repo,
|
||||
"closure-source-grounded",
|
||||
"Prove default closure verification cites the changed path.",
|
||||
None,
|
||||
)?;
|
||||
let bad = drive_item(
|
||||
&manifest,
|
||||
&root,
|
||||
&repo,
|
||||
"closure-proofless-output",
|
||||
"Prove source grounding blocks proofless verification output.",
|
||||
Some("Write-Output 'ok'"),
|
||||
)?;
|
||||
|
||||
require_eq(&good.close, &["status"], "closed")?;
|
||||
require_eq(&good.close, &["soul", "verdict"], "passed")?;
|
||||
require_bool(
|
||||
&good.close,
|
||||
&[
|
||||
"closureReview",
|
||||
"verificationSourceGrounding",
|
||||
"allDeclaredPathsMentionedByVerificationOutput",
|
||||
],
|
||||
true,
|
||||
)?;
|
||||
require_bool(
|
||||
&good.close,
|
||||
&["closureReview", "verificationSourceGrounding", "required"],
|
||||
true,
|
||||
)?;
|
||||
require_eq(&bad.close, &["status"], "verification-failed")?;
|
||||
require_eq(&bad.close, &["soul", "verdict"], "failed")?;
|
||||
require_eq(
|
||||
&bad.close,
|
||||
&["closureReview", "verificationSourceGrounding", "status"],
|
||||
"failed",
|
||||
)?;
|
||||
require_bool(
|
||||
&bad.close,
|
||||
&[
|
||||
"closureReview",
|
||||
"verificationSourceGrounding",
|
||||
"allDeclaredPathsMentionedByVerificationOutput",
|
||||
],
|
||||
false,
|
||||
)?;
|
||||
require_bool(
|
||||
&bad.close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(
|
||||
&bad.close,
|
||||
&[
|
||||
"closureReview",
|
||||
"sourceGrounding",
|
||||
"verificationOutputMentionsChangedPaths",
|
||||
],
|
||||
false,
|
||||
)?;
|
||||
require_eq(
|
||||
&bad.close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(&good.close, &["privateStateExposed"], false)?;
|
||||
require_bool(&bad.close, &["privateStateExposed"], false)?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_work_closure_source_grounding_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"passItem": good.item,
|
||||
"passCloseStatus": good.close["status"],
|
||||
"passSourceGroundingStatus": good.close["closureReview"]["verificationSourceGrounding"]["status"],
|
||||
"passVerificationOutputMentionsChangedPaths": good.close["closureReview"]["sourceGrounding"]["verificationOutputMentionsChangedPaths"],
|
||||
"blockItem": bad.item,
|
||||
"blockCloseStatus": bad.close["status"],
|
||||
"blockSoulVerdict": bad.close["soul"]["verdict"],
|
||||
"blockSourceGroundingStatus": bad.close["closureReview"]["verificationSourceGrounding"]["status"],
|
||||
"blockPathScopeMatched": bad.close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"blockFamilyAssertionsStatus": bad.close["closureReview"]["familyAssertions"]["status"],
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
struct ItemProof {
|
||||
item: String,
|
||||
close: Value,
|
||||
}
|
||||
|
||||
fn drive_item(
|
||||
manifest: &Path,
|
||||
root: &Path,
|
||||
repo: &Path,
|
||||
item: &str,
|
||||
summary: &str,
|
||||
verification_command: Option<&str>,
|
||||
) -> Result<ItemProof> {
|
||||
cargo_json(
|
||||
manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
summary,
|
||||
],
|
||||
root,
|
||||
)?;
|
||||
cargo_json(
|
||||
manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-status-section",
|
||||
"--model-ref",
|
||||
"closure-source-grounding-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
root,
|
||||
)?;
|
||||
for _ in 0..3 {
|
||||
cargo_json(
|
||||
manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
root,
|
||||
)?;
|
||||
}
|
||||
|
||||
let mut close_args = vec![
|
||||
"close".to_string(),
|
||||
"--workspace".to_string(),
|
||||
path_str(repo)?.to_string(),
|
||||
"--item".to_string(),
|
||||
item.to_string(),
|
||||
"--require-source-grounding".to_string(),
|
||||
];
|
||||
if let Some(command) = verification_command {
|
||||
close_args.push("--verification-command".to_string());
|
||||
close_args.push(command.to_string());
|
||||
}
|
||||
let close_arg_refs = close_args.iter().map(String::as_str).collect::<Vec<_>>();
|
||||
let close = cargo_json(manifest, "epiphany-work", &close_arg_refs, root)?;
|
||||
Ok(ItemProof {
|
||||
item: item.to_string(),
|
||||
close,
|
||||
})
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git output failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
||||
fn take_path(args: &mut impl Iterator<Item = String>, name: &str) -> Result<PathBuf> {
|
||||
Ok(PathBuf::from(
|
||||
args.next()
|
||||
.ok_or_else(|| anyhow!("missing value for {name}"))?,
|
||||
))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = value_at(value, path)
|
||||
.and_then(Value::as_str)
|
||||
.ok_or_else(|| anyhow!("missing string at {}", path.join(".")))?;
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = value_at(value, path)
|
||||
.and_then(Value::as_bool)
|
||||
.ok_or_else(|| anyhow!("missing bool at {}", path.join(".")))?;
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {actual}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn value_at<'a>(value: &'a Value, path: &[&str]) -> Option<&'a Value> {
|
||||
let mut current = value;
|
||||
for segment in path {
|
||||
current = current.get(*segment)?;
|
||||
}
|
||||
Some(current)
|
||||
}
|
||||
|
|
@ -1,447 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-credit-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Credit Request Family Smoke\n\nThis repository proves branch-local Bifrost credit request cargo without credit ledger authority.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed repo credit request smoke body"],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
["switch", "-c", "epiphany/repo-credit-request-family"],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-credit-request-family";
|
||||
let target_path = ".epiphany/credit-requests/repo-credit-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-credit-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-credit-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-credit-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask Bifrost to prepare credit ledger review for an accepted artifact without granting credit authority.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-credit-request-family/credit-packet",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-credit-request-family/bifrost-ledger-review",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-credit-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-credit-request",
|
||||
"--model-ref",
|
||||
"repo-credit-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.credit_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_credit_request.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"safe_action_family = \"repo.credit_request\"",
|
||||
)?;
|
||||
require_text(&request_text, "[request]")?;
|
||||
require_text(&request_text, "status = \"awaiting-bifrost-credit-review\"")?;
|
||||
require_text(&request_text, "requested_owner = \"Bifrost\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requested_effect = \"record-credit-for-redacted-proof-and-accepted-artifact\"",
|
||||
)?;
|
||||
require_text(&request_text, "maintainer_review_request_ref = ")?;
|
||||
require_text(&request_text, "publication_request_ref = ")?;
|
||||
require_text(&request_text, "pr_request_ref = ")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"credit_scope = \"authorship, maintainer review, accepted artifact, public proof, and Bifrost ledger readback\"",
|
||||
)?;
|
||||
require_text(&request_text, "[antecedents]")?;
|
||||
require_text(&request_text, "closure_review_required = true")?;
|
||||
require_text(&request_text, "soul_verdict_required = true")?;
|
||||
require_text(&request_text, "mind_commit_required = true")?;
|
||||
require_text(&request_text, "public_proof_required = true")?;
|
||||
require_text(&request_text, "maintainer_review_required = true")?;
|
||||
require_text(&request_text, "accepted_artifact_required = true")?;
|
||||
require_text(&request_text, "authorship_context_required = true")?;
|
||||
require_text(&request_text, "[required_receipts]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"closure_review = \"epiphany.repo_work_closure_review.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"soul_verdict = \"epiphany.soul.verification_verdict\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"mind_commit = \"epiphany.mind.state_commit_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"public_proof = \"epiphany.repo_work_public_proof_bundle.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"maintainer_review = \"gamecult.maintainer.review_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"accepted_artifact = \"gamecult.artifact.acceptance_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"credit_ledger = \"gamecult.bifrost.credit_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"credit_readback = \"gamecult.bifrost.credit_readback_receipt.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "[credit_packet]")?;
|
||||
require_text(&request_text, "requires_author_identity = true")?;
|
||||
require_text(&request_text, "requires_reviewer_identity = true")?;
|
||||
require_text(&request_text, "requires_accepted_artifact_ref = true")?;
|
||||
require_text(&request_text, "requires_changed_path_list = true")?;
|
||||
require_text(&request_text, "requires_public_proof_ref = true")?;
|
||||
require_text(&request_text, "requires_credit_ledger_target = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requires_private_state_redaction_check = true",
|
||||
)?;
|
||||
require_text(&request_text, "credit_ledger_authorized = false")?;
|
||||
require_text(&request_text, "bifrost_publication_authorized = false")?;
|
||||
require_text(&request_text, "github_pr_authorized = false")?;
|
||||
require_text(&request_text, "merge_authorized = false")?;
|
||||
require_text(&request_text, "publication_authorized = false")?;
|
||||
require_text(&request_text, "upstream_sync_authorized = false")?;
|
||||
require_text(&request_text, "hands_action_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "bifrost_credit_authority_required = true")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_credit_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingBifrostCreditReview": true,
|
||||
"creditLedgerAuthorized": false,
|
||||
"bifrostPublicationAuthorized": false,
|
||||
"githubPrAuthorized": false,
|
||||
"mergeAuthorized": false,
|
||||
"publicationAuthorized": false,
|
||||
"upstreamSyncAuthorized": false,
|
||||
"handsActionAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected credit request text to contain {needle:?}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,430 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-dependency-policy-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Dependency Policy Request Family Smoke\n\nThis repository proves branch-local dependency policy request cargo without package install authority.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
fs::write(
|
||||
repo.join("package.json"),
|
||||
"{\n \"name\": \"epiphany-dependency-policy-smoke\",\n \"version\": \"0.0.0\",\n \"dependencies\": {}\n}\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("package.json").display()))?;
|
||||
fs::write(
|
||||
repo.join("Cargo.toml"),
|
||||
"[package]\nname = \"epiphany-dependency-policy-smoke\"\nversion = \"0.0.0\"\nedition = \"2024\"\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("Cargo.toml").display()))?;
|
||||
git(["add", "README.md", "package.json", "Cargo.toml"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed repo dependency policy smoke body"],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
[
|
||||
"switch",
|
||||
"-c",
|
||||
"epiphany/repo-dependency-policy-request-family",
|
||||
],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-dependency-policy-request-family";
|
||||
let target_path =
|
||||
".epiphany/dependency-policy-requests/repo-dependency-policy-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-dependency-policy-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-dependency-policy-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-dependency-policy-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask for a reviewed dependency and supply-chain policy before changing package manifests or lockfiles.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-dependency-policy-request-family/dependency-review",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-dependency-policy-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-dependency-policy-request",
|
||||
"--model-ref",
|
||||
"repo-dependency-policy-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
|
||||
let close = read_json(
|
||||
&repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json")),
|
||||
)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
let package_text = fs::read_to_string(repo.join("package.json"))
|
||||
.with_context(|| format!("failed to read {}", repo.join("package.json").display()))?;
|
||||
let cargo_text = fs::read_to_string(repo.join("Cargo.toml"))
|
||||
.with_context(|| format!("failed to read {}", repo.join("Cargo.toml").display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.dependency_policy_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_dependency_policy_request.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"safe_action_family = \"repo.dependency_policy_request\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"status = \"awaiting-dependency-policy-review\"",
|
||||
)?;
|
||||
require_text(&request_text, "routing_owner = \"Self\"")?;
|
||||
require_text(&request_text, "requires_manifest_inventory = true")?;
|
||||
require_text(&request_text, "requires_lockfile_policy = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requires_package_manager_command_review = true",
|
||||
)?;
|
||||
require_text(&request_text, "requires_network_fetch_policy = true")?;
|
||||
require_text(&request_text, "requires_vulnerability_review = true")?;
|
||||
require_text(&request_text, "requires_license_review = true")?;
|
||||
require_text(&request_text, "source_grounding_required = true")?;
|
||||
require_text(&request_text, "eyes_evidence_required = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"dependency_audit = \"gamecult.supply_chain.dependency_audit_receipt.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "requires_manifest_paths = true")?;
|
||||
require_text(&request_text, "requires_lockfile_paths = true")?;
|
||||
require_text(&request_text, "requires_package_manager_commands = true")?;
|
||||
require_text(&request_text, "requires_vulnerability_sources = true")?;
|
||||
require_text(&request_text, "requires_license_constraints = true")?;
|
||||
require_text(&request_text, "requires_vendored_code_policy = true")?;
|
||||
require_text(&request_text, "requires_update_cadence = true")?;
|
||||
require_text(&request_text, "direct_dependency_update_authority = false")?;
|
||||
require_text(&request_text, "direct_package_install_authority = false")?;
|
||||
require_text(&request_text, "direct_lockfile_mutation_authority = false")?;
|
||||
require_text(&request_text, "direct_network_fetch_authority = false")?;
|
||||
require_text(&request_text, "direct_ci_mutation_authority = false")?;
|
||||
require_text(&request_text, "direct_hands_authority = false")?;
|
||||
require_text(&request_text, "publication_authorized = false")?;
|
||||
require_text(&request_text, "deployment_authority = false")?;
|
||||
require_text(&request_text, "service_lifecycle_authority = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "private_verse_rummaging = false")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
require_text(&package_text, "\"dependencies\": {}")?;
|
||||
require_text(&cargo_text, "edition = \"2024\"")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_dependency_policy_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingDependencyPolicyReview": true,
|
||||
"dependencyUpdateAuthorized": false,
|
||||
"packageInstallAuthorized": false,
|
||||
"lockfileMutationAuthorized": false,
|
||||
"networkFetchAuthorized": false,
|
||||
"ciMutationAuthorized": false,
|
||||
"deploymentAuthority": false,
|
||||
"publicationAuthorized": false,
|
||||
"serviceLifecycleAuthority": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to equal {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false);
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to equal {expected}, got {actual}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(text: &str, needle: &str) -> Result<()> {
|
||||
if text.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("expected text to contain {needle:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.ok_or_else(|| anyhow!("missing value for {flag}"))
|
||||
}
|
||||
|
|
@ -1,437 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-deployment-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Deployment Request Family Smoke\n\nThis repository proves branch-local deployment request cargo without deploy authority.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
fs::create_dir_all(repo.join("deploy"))
|
||||
.with_context(|| format!("failed to create {}", repo.join("deploy").display()))?;
|
||||
fs::write(
|
||||
repo.join("deploy").join("idunn-deploy.ps1"),
|
||||
"# reviewed by Idunn before use\nWrite-Output 'deployment script placeholder'\n",
|
||||
)
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"failed to seed {}",
|
||||
repo.join("deploy").join("idunn-deploy.ps1").display()
|
||||
)
|
||||
})?;
|
||||
git(["add", "README.md", "deploy/idunn-deploy.ps1"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed repo deployment request smoke body"],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
["switch", "-c", "epiphany/repo-deployment-request-family"],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-deployment-request-family";
|
||||
let target_path = ".epiphany/deployment-requests/repo-deployment-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-deployment-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-deployment-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-deployment-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask for a reviewed Idunn-owned git-push deployment request without granting deployment authority.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-deployment-request-family/idunn-review",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-deployment-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-deployment-request",
|
||||
"--model-ref",
|
||||
"repo-deployment-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
|
||||
let close = read_json(
|
||||
&repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json")),
|
||||
)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
let deploy_script_text = fs::read_to_string(repo.join("deploy").join("idunn-deploy.ps1"))
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"failed to read {}",
|
||||
repo.join("deploy").join("idunn-deploy.ps1").display()
|
||||
)
|
||||
})?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.deployment_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_deployment_request.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"safe_action_family = \"repo.deployment_request\"",
|
||||
)?;
|
||||
require_text(&request_text, "status = \"awaiting-idunn-review\"")?;
|
||||
require_text(&request_text, "routing_owner = \"Self\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"required_reviewers = [\"Maintainer\", \"Soul\", \"Mind\", \"Bifrost\"]",
|
||||
)?;
|
||||
require_text(&request_text, "execution_owner = \"Idunn\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"deployment_trigger = \"git-push-observed-by-idunn\"",
|
||||
)?;
|
||||
require_text(&request_text, "requires_idunn_receipt = true")?;
|
||||
require_text(&request_text, "requires_aftercare_audit = true")?;
|
||||
require_text(&request_text, "secret_policy_review_required = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"idunn_deployment = \"gamecult.idunn.deployment_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"aftercare_audit = \"gamecult.idunn.deployment_aftercare_audit.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "requires_deployment_script_ref = true")?;
|
||||
require_text(&request_text, "requires_watched_ref = true")?;
|
||||
require_text(&request_text, "requires_source_commit_sha = true")?;
|
||||
require_text(&request_text, "requires_script_hash = true")?;
|
||||
require_text(&request_text, "requires_script_review_ref = true")?;
|
||||
require_text(&request_text, "requires_host_access_policy_ref = true")?;
|
||||
require_text(&request_text, "requires_secret_policy_ref = true")?;
|
||||
require_text(&request_text, "requires_rollback_plan = true")?;
|
||||
require_text(&request_text, "requires_aftercare_checks = true")?;
|
||||
require_text(&request_text, "direct_deployment_authority = false")?;
|
||||
require_text(&request_text, "direct_ssh_authority = false")?;
|
||||
require_text(&request_text, "direct_git_push_authority = false")?;
|
||||
require_text(&request_text, "direct_service_lifecycle_authority = false")?;
|
||||
require_text(&request_text, "direct_hands_authority = false")?;
|
||||
require_text(&request_text, "publication_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "private_verse_rummaging = false")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
require_text(&deploy_script_text, "deployment script placeholder")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_deployment_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingIdunnReview": true,
|
||||
"deploymentTrigger": "git-push-observed-by-idunn",
|
||||
"deploymentAuthority": false,
|
||||
"sshAuthority": false,
|
||||
"gitPushAuthority": false,
|
||||
"serviceLifecycleAuthority": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = value_at_path(value, path)
|
||||
.and_then(Value::as_str)
|
||||
.ok_or_else(|| anyhow!("missing string at {}", path.join(".")))?;
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {:?}, got {:?}",
|
||||
path.join("."),
|
||||
expected,
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = value_at_path(value, path)
|
||||
.and_then(Value::as_bool)
|
||||
.ok_or_else(|| anyhow!("missing bool at {}", path.join(".")))?;
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {}, got {}",
|
||||
path.join("."),
|
||||
expected,
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("expected text to contain {needle:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
fn value_at_path<'a>(value: &'a Value, path: &[&str]) -> Option<&'a Value> {
|
||||
let mut cursor = value;
|
||||
for segment in path {
|
||||
if let Ok(index) = segment.parse::<usize>() {
|
||||
cursor = cursor.as_array()?.get(index)?;
|
||||
} else {
|
||||
cursor = cursor.get(*segment)?;
|
||||
}
|
||||
}
|
||||
Some(cursor)
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
||||
fn take_path(args: &mut impl Iterator<Item = String>, name: &str) -> Result<PathBuf> {
|
||||
Ok(PathBuf::from(
|
||||
args.next()
|
||||
.ok_or_else(|| anyhow!("missing value for {name}"))?,
|
||||
))
|
||||
}
|
||||
|
|
@ -1,437 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-interpreter-brief-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Interpreter Brief Family Smoke\n\nThis repository proves branch-local Mind-owned interpretation briefs.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed repo interpreter brief smoke body"],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
["switch", "-c", "epiphany/repo-interpreter-brief-family"],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-interpreter-brief-family";
|
||||
let target_path = ".epiphany/interpreter-briefs/repo-interpreter-brief-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-interpreter-brief-family-smoke",
|
||||
"--topic",
|
||||
"repo-interpreter-brief-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-interpreter-brief-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Turn rough Persona and Imagination consensus into a Mind-owned interpreter brief before any work item receives Hands authority.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-interpreter-brief-family/interpret-action-semantics",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-interpreter-brief-family/request-soul-grounding",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-interpreter-brief-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-interpreter-brief",
|
||||
"--model-ref",
|
||||
"repo-interpreter-brief-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let brief_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.interpreter_brief",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&brief_text,
|
||||
"schema_version = \"epiphany.repo_interpreter_brief.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&brief_text,
|
||||
"safe_action_family = \"repo.interpreter_brief\"",
|
||||
)?;
|
||||
require_text(&brief_text, "[interpreter]")?;
|
||||
require_text(&brief_text, "status = \"awaiting-mind-interpretation\"")?;
|
||||
require_text(&brief_text, "authoring_owner = \"Imagination\"")?;
|
||||
require_text(&brief_text, "requested_interpreter = \"Mind\"")?;
|
||||
require_text(&brief_text, "interpretation_admitted = false")?;
|
||||
require_text(
|
||||
&brief_text,
|
||||
"purpose = \"public-pressure-to-action-semantics\"",
|
||||
)?;
|
||||
require_text(&brief_text, "requires_consensus_readback = true")?;
|
||||
require_text(&brief_text, "requires_safe_family_choice = true")?;
|
||||
require_text(&brief_text, "requires_requested_paths = true")?;
|
||||
require_text(&brief_text, "requires_verification_asks = true")?;
|
||||
require_text(&brief_text, "requires_evidence_needs = true")?;
|
||||
require_text(&brief_text, "candidate_actions_non_authoritative = true")?;
|
||||
require_text(&brief_text, "[semantic_checks]")?;
|
||||
require_text(&brief_text, "intent_summary_required = true")?;
|
||||
require_text(&brief_text, "scope_boundary_required = true")?;
|
||||
require_text(&brief_text, "requested_paths_required = true")?;
|
||||
require_text(&brief_text, "verification_required = true")?;
|
||||
require_text(&brief_text, "evidence_required = true")?;
|
||||
require_text(&brief_text, "rollback_required = true")?;
|
||||
require_text(&brief_text, "non_goals_required = true")?;
|
||||
require_text(&brief_text, "open_questions_required = true")?;
|
||||
require_text(&brief_text, "consensus_alignment_required = true")?;
|
||||
require_text(&brief_text, "[allowed_outputs]")?;
|
||||
require_text(&brief_text, "\"repo.consensus_brief\"")?;
|
||||
require_text(&brief_text, "\"repo.objective_draft\"")?;
|
||||
require_text(&brief_text, "\"repo.adoption_request\"")?;
|
||||
require_text(&brief_text, "\"repo.work_order\"")?;
|
||||
require_text(&brief_text, "\"repo.verification_request\"")?;
|
||||
require_text(&brief_text, "\"repo.publication_request\"")?;
|
||||
require_text(&brief_text, "may_request_replanning = true")?;
|
||||
require_text(&brief_text, "may_request_more_consensus = true")?;
|
||||
require_text(&brief_text, "may_adopt_objective = false")?;
|
||||
require_text(&brief_text, "may_schedule_work = false")?;
|
||||
require_text(&brief_text, "may_touch_substrate = false")?;
|
||||
require_text(&brief_text, "may_publish = false")?;
|
||||
require_text(&brief_text, "may_deploy = false")?;
|
||||
require_text(&brief_text, "[required_gates]")?;
|
||||
require_text(&brief_text, "imagination_consensus_required = true")?;
|
||||
require_text(&brief_text, "mind_review_required = true")?;
|
||||
require_text(&brief_text, "soul_source_grounding_required = true")?;
|
||||
require_text(&brief_text, "bifrost_publication_review_required = true")?;
|
||||
require_text(
|
||||
&brief_text,
|
||||
"hands_receipt_required_before_state_change = true",
|
||||
)?;
|
||||
require_text(
|
||||
&brief_text,
|
||||
"substrate_receipt_required_before_mutation = true",
|
||||
)?;
|
||||
require_text(
|
||||
&brief_text,
|
||||
"idunn_receipt_required_before_deployment = true",
|
||||
)?;
|
||||
require_text(&brief_text, "direct_state_commit_authorized = false")?;
|
||||
require_text(&brief_text, "objective_adoption_authorized = false")?;
|
||||
require_text(&brief_text, "self_scheduling_authorized = false")?;
|
||||
require_text(&brief_text, "substrate_access_authorized = false")?;
|
||||
require_text(&brief_text, "hands_action_authorized = false")?;
|
||||
require_text(&brief_text, "shell_command_authorized = false")?;
|
||||
require_text(&brief_text, "commit_authorized = false")?;
|
||||
require_text(&brief_text, "publication_authorized = false")?;
|
||||
require_text(&brief_text, "deployment_execution_authority = false")?;
|
||||
require_text(&brief_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&brief_text, "private_worker_transcripts_allowed = false")?;
|
||||
require_text(&brief_text, "raw_result_payloads_allowed = false")?;
|
||||
require_text(&brief_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_work_interpreter_brief_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"interpreterIsDraft": true,
|
||||
"mindOwnsInterpretation": true,
|
||||
"candidateActionsNonAuthoritative": true,
|
||||
"directStateCommitAuthorized": false,
|
||||
"handsActionAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected interpreter brief text to contain {needle:?}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,299 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Args {
|
||||
workspace: PathBuf,
|
||||
item: String,
|
||||
expected_path: String,
|
||||
expected_family: String,
|
||||
expected_gate: String,
|
||||
expected_blocker: String,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut workspace = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut item = None;
|
||||
let mut expected_path = "README.md".to_string();
|
||||
let mut expected_family = "repo.status_section".to_string();
|
||||
let mut expected_gate = "awaiting-publication".to_string();
|
||||
let mut expected_blocker = "bifrost-publication-missing".to_string();
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--workspace" => workspace = take_path(&mut args, "--workspace")?,
|
||||
"--item" => item = Some(take_value(&mut args, "--item")?),
|
||||
"--expected-path" => expected_path = take_value(&mut args, "--expected-path")?,
|
||||
"--expected-family" => {
|
||||
expected_family = take_value(&mut args, "--expected-family")?
|
||||
}
|
||||
"--expected-gate" => expected_gate = take_value(&mut args, "--expected-gate")?,
|
||||
"--expected-blocker" => {
|
||||
expected_blocker = take_value(&mut args, "--expected-blocker")?
|
||||
}
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
let item = item.ok_or_else(|| anyhow!("--item is required"))?;
|
||||
Ok(Self {
|
||||
workspace,
|
||||
item,
|
||||
expected_path,
|
||||
expected_family,
|
||||
expected_gate,
|
||||
expected_blocker,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let workspace = args
|
||||
.workspace
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.workspace.display()))?;
|
||||
let work_dir = workspace.join(".epiphany").join("work");
|
||||
let close_path = work_dir.join(format!("work-close-{}.json", args.item));
|
||||
let overview_path = work_dir.join(format!("work-overview-{}.json", args.item));
|
||||
let close = read_json(&close_path)?;
|
||||
let overview = read_json(&overview_path)?;
|
||||
|
||||
require_str(
|
||||
&close,
|
||||
&["schemaVersion"],
|
||||
"epiphany.repo_work_closure_receipt.v0",
|
||||
)?;
|
||||
require_str(&close, &["status"], "closed")?;
|
||||
require_str(&close, &["item"], &args.item)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_str(&close, &["soul", "verdict"], "passed")?;
|
||||
require_bool(&close, &["authority", "branchLocalOnly"], true)?;
|
||||
require_bool(&close, &["authority", "publicationAuthorized"], false)?;
|
||||
require_bool(&close, &["authority", "mergeAuthorized"], false)?;
|
||||
require_bool(&close, &["authority", "serviceLifecycleAuthorized"], false)?;
|
||||
require_bool(&close, &["authority", "crossRepoMutationAuthorized"], false)?;
|
||||
require_bool(&close, &["authority", "privateStateExposed"], false)?;
|
||||
require_str(
|
||||
&close,
|
||||
&["mind", "repoMapEntry", "safeActionFamily"],
|
||||
&args.expected_family,
|
||||
)?;
|
||||
require_str(
|
||||
&close,
|
||||
&["mind", "repoMapEntry", "publicationGate"],
|
||||
"Bifrost",
|
||||
)?;
|
||||
let commit_sha = require_present_str(&close, &["handsReceipts", "commitSha"])?;
|
||||
require_single_path(
|
||||
&close,
|
||||
&["mind", "repoMapEntry", "changedPaths"],
|
||||
&args.expected_path,
|
||||
)?;
|
||||
require_single_path(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "actualChangedPaths"],
|
||||
&args.expected_path,
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "familyAssertionsPassed"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "mindAdoptionPassed"],
|
||||
true,
|
||||
)?;
|
||||
|
||||
let overview_schema = require_one_of_str(
|
||||
&overview,
|
||||
&["schemaVersion"],
|
||||
&[
|
||||
"epiphany.repo_work_overview.v0",
|
||||
"epiphany.repo_work_overview_receipt.v0",
|
||||
],
|
||||
)?;
|
||||
if overview_schema == "epiphany.repo_work_overview.v0" {
|
||||
require_str(&overview, &["status"], "overview-ready")?;
|
||||
}
|
||||
require_str(&overview, &["item"], &args.item)?;
|
||||
require_str(&overview, &["currentGate"], &args.expected_gate)?;
|
||||
require_str(&overview, &["blocker"], &args.expected_blocker)?;
|
||||
require_bool(&overview, &["privateStateExposed"], false)?;
|
||||
require_str(&overview, &["proofBundle", "soulVerdict"], "passed")?;
|
||||
require_single_path(
|
||||
&overview,
|
||||
&["proofBundle", "changedPaths"],
|
||||
&args.expected_path,
|
||||
)?;
|
||||
|
||||
let git_paths = git_changed_paths(&workspace, commit_sha)?;
|
||||
if git_paths != vec![args.expected_path.clone()] {
|
||||
return Err(anyhow!(
|
||||
"expected git commit {commit_sha} to change only {:?}, got {:?}",
|
||||
args.expected_path,
|
||||
git_paths
|
||||
));
|
||||
}
|
||||
|
||||
Ok(json!({
|
||||
"schemaVersion": "epiphany.repo_livefire_closure_smoke.v0",
|
||||
"status": "ok",
|
||||
"workspace": workspace,
|
||||
"item": args.item,
|
||||
"branch": string_at(&close, &["mind", "repoMapEntry", "branch"]),
|
||||
"commitSha": commit_sha,
|
||||
"safeActionFamily": args.expected_family,
|
||||
"changedPaths": git_paths,
|
||||
"currentGate": args.expected_gate,
|
||||
"blocker": args.expected_blocker,
|
||||
"publicationGate": "Bifrost",
|
||||
"soulVerdict": "passed",
|
||||
"mindStateCommitReceiptId": string_at(&close, &["mind", "stateCommitReceiptId"]),
|
||||
"closeReceipt": close_path,
|
||||
"overviewReceipt": overview_path,
|
||||
"verifiedAt": Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
|
||||
"privateStateExposed": false,
|
||||
}))
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn take_value(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
name: &str,
|
||||
) -> Result<String> {
|
||||
args.next()
|
||||
.ok_or_else(|| anyhow!("missing value for {name}"))
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
name: &str,
|
||||
) -> Result<PathBuf> {
|
||||
Ok(PathBuf::from(take_value(args, name)?))
|
||||
}
|
||||
|
||||
fn value_at<'a>(value: &'a Value, path: &[&str]) -> Option<&'a Value> {
|
||||
path.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
}
|
||||
|
||||
fn string_at(value: &Value, path: &[&str]) -> String {
|
||||
value_at(value, path)
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>")
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn require_present_str<'a>(value: &'a Value, path: &[&str]) -> Result<&'a str> {
|
||||
value_at(value, path)
|
||||
.and_then(Value::as_str)
|
||||
.filter(|actual| !actual.is_empty())
|
||||
.ok_or_else(|| anyhow!("expected {} to be a non-empty string", path.join(".")))
|
||||
}
|
||||
|
||||
fn require_str(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = string_at(value, path);
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_one_of_str<'a>(value: &Value, path: &[&str], expected: &'a [&str]) -> Result<&'a str> {
|
||||
let actual = string_at(value, path);
|
||||
if let Some(matched) = expected.iter().find(|candidate| **candidate == actual) {
|
||||
Ok(*matched)
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be one of {:?}, got {actual:?}",
|
||||
path.join("."),
|
||||
expected
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = value_at(value, path).and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_single_path(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let paths = value_at(value, path)
|
||||
.and_then(Value::as_array)
|
||||
.ok_or_else(|| anyhow!("expected {} to be an array", path.join(".")))?
|
||||
.iter()
|
||||
.map(|entry| entry.as_str().unwrap_or("<non-string>").to_string())
|
||||
.collect::<Vec<_>>();
|
||||
if paths == vec![expected.to_string()] {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to contain only {expected:?}, got {:?}",
|
||||
path.join("."),
|
||||
paths
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_changed_paths(workspace: &Path, commit_sha: &str) -> Result<Vec<String>> {
|
||||
let output = Command::new("git")
|
||||
.arg("-C")
|
||||
.arg(workspace)
|
||||
.arg("show")
|
||||
.arg("--format=")
|
||||
.arg("--name-only")
|
||||
.arg(commit_sha)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git show in {}", workspace.display()))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"git show failed with exit {:?}: {}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
Ok(String::from_utf8_lossy(&output.stdout)
|
||||
.lines()
|
||||
.map(str::trim)
|
||||
.filter(|line| !line.is_empty())
|
||||
.map(|line| line.replace('\\', "/"))
|
||||
.collect())
|
||||
}
|
||||
|
|
@ -1,444 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-maintainer-review-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Maintainer Review Request Family Smoke\n\nThis repository proves branch-local Hands maintainer-review-request requests.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(
|
||||
[
|
||||
"commit",
|
||||
"-m",
|
||||
"Seed repo maintainer review request smoke body",
|
||||
],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
[
|
||||
"switch",
|
||||
"-c",
|
||||
"epiphany/repo-maintainer-review-request-family",
|
||||
],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-maintainer-review-request-family";
|
||||
let target_path = ".epiphany/review-requests/repo-maintainer-review-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-maintainer-review-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-maintainer-review-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-maintainer-review-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask a maintainer to review the redacted proof and branch diff without granting merge authority.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-maintainer-review-request-family/human-review",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-maintainer-review-request-family/maintainer-verdict",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-maintainer-review-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-maintainer-review-request",
|
||||
"--model-ref",
|
||||
"repo-maintainer-review-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.maintainer_review_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_maintainer_review_request.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"safe_action_family = \"repo.maintainer_review_request\"",
|
||||
)?;
|
||||
require_text(&request_text, "[request]")?;
|
||||
require_text(&request_text, "status = \"awaiting-maintainer-review\"")?;
|
||||
require_text(&request_text, "requested_owner = \"Maintainer\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requested_effect = \"review-redacted-proof-and-branch-diff\"",
|
||||
)?;
|
||||
require_text(&request_text, "verification_request_ref = ")?;
|
||||
require_text(&request_text, "publication_request_ref = ")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"review_scope = \"changed paths, closure proof, public proof bundle, and Bifrost credit context\"",
|
||||
)?;
|
||||
require_text(&request_text, "[antecedents]")?;
|
||||
require_text(&request_text, "closure_review_required = true")?;
|
||||
require_text(&request_text, "soul_verdict_required = true")?;
|
||||
require_text(&request_text, "mind_commit_required = true")?;
|
||||
require_text(&request_text, "public_proof_required = true")?;
|
||||
require_text(&request_text, "bifrost_publication_request_required = true")?;
|
||||
require_text(&request_text, "[required_receipts]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"closure_review = \"epiphany.repo_work_closure_review.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"soul_verdict = \"epiphany.soul.verification_verdict\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"mind_commit = \"epiphany.mind.state_commit_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"public_proof = \"epiphany.repo_work_public_proof_bundle.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"maintainer_review = \"gamecult.maintainer.review_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"bifrost_publication = \"gamecult.bifrost.public_proof_publication_receipt.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "[review_packet]")?;
|
||||
require_text(&request_text, "requires_reviewer_identity = true")?;
|
||||
require_text(&request_text, "requires_review_verdict = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"allowed_verdicts = [\"approved\", \"changes-requested\", \"rejected\", \"needs-human-context\"]",
|
||||
)?;
|
||||
require_text(&request_text, "requires_changed_path_list = true")?;
|
||||
require_text(&request_text, "requires_public_proof_ref = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requires_private_state_redaction_check = true",
|
||||
)?;
|
||||
require_text(&request_text, "maintainer_approval_authorized = false")?;
|
||||
require_text(&request_text, "maintainer_response_required = true")?;
|
||||
require_text(&request_text, "merge_authorized = false")?;
|
||||
require_text(&request_text, "push_authorized = false")?;
|
||||
require_text(&request_text, "publication_authorized = false")?;
|
||||
require_text(&request_text, "upstream_sync_authorized = false")?;
|
||||
require_text(&request_text, "hands_action_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_maintainer_review_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingMaintainerReview": true,
|
||||
"maintainerApprovalAuthorized": false,
|
||||
"mergeAuthorized": false,
|
||||
"pushAuthorized": false,
|
||||
"publicationAuthorized": false,
|
||||
"upstreamSyncAuthorized": false,
|
||||
"handsActionAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected maintainer review request text to contain {needle:?}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,391 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-objective-draft-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Objective Draft Family Smoke\n\nThis repository proves branch-local Objective Draft cargo.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed repo objective draft smoke body"],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
["switch", "-c", "epiphany/repo-objective-draft-family"],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-objective-draft-family";
|
||||
let target_path = ".epiphany/objective-drafts/repo-objective-draft-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-objective-draft-family-smoke",
|
||||
"--topic",
|
||||
"repo-objective-draft-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-objective-draft-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Shape public consensus into a reviewable Objective Draft before Self schedules any branch-local work.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-objective-draft-family/adopt-objective",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-objective-draft-family/write-task-card",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-objective-draft-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-objective-draft",
|
||||
"--model-ref",
|
||||
"repo-objective-draft-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let draft_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.objective_draft",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&draft_text,
|
||||
"schema_version = \"epiphany.repo_objective_draft.v0\"",
|
||||
)?;
|
||||
require_text(&draft_text, "safe_action_family = \"repo.objective_draft\"")?;
|
||||
require_text(&draft_text, "[draft]")?;
|
||||
require_text(&draft_text, "status = \"review-required\"")?;
|
||||
require_text(&draft_text, "adoption_gate = \"Mind\"")?;
|
||||
require_text(&draft_text, "scheduler_gate = \"Self\"")?;
|
||||
require_text(&draft_text, "publication_gate = \"Bifrost\"")?;
|
||||
require_text(&draft_text, "objective_adopted = false")?;
|
||||
require_text(&draft_text, "[objective]")?;
|
||||
require_text(
|
||||
&draft_text,
|
||||
"preferred_next_safe_family = \"repo.task_card\"",
|
||||
)?;
|
||||
require_text(&draft_text, "[acceptance]")?;
|
||||
require_text(&draft_text, "Mind explicitly accepts or rejects")?;
|
||||
require_text(&draft_text, "Self schedules only after Mind adoption")?;
|
||||
require_text(
|
||||
&draft_text,
|
||||
"Hands acts only through a later receipt-backed plan",
|
||||
)?;
|
||||
require_text(&draft_text, "[inputs]")?;
|
||||
require_text(&draft_text, "consensus_brief_required = true")?;
|
||||
require_text(&draft_text, "objective_adoption_authorized = false")?;
|
||||
require_text(&draft_text, "self_scheduling_authorized = false")?;
|
||||
require_text(&draft_text, "hands_action_authorized = false")?;
|
||||
require_text(&draft_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&draft_text, "mind_adoption_required = true")?;
|
||||
require_text(&draft_text, "bifrost_publication_required = true")?;
|
||||
require_text(&draft_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_work_objective_draft_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"draftReviewRequired": true,
|
||||
"objectiveAdopted": false,
|
||||
"mindAdoptionRequired": true,
|
||||
"selfSchedulingAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected Objective Draft text to contain {needle:?}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,788 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use epiphany_core::load_agent_memory_entry_for_role;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let result = run_smoke()?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_smoke() -> Result<Value> {
|
||||
let root = env::current_dir().context("failed to resolve current dir")?;
|
||||
let workspace = root
|
||||
.join(".epiphany-smoke")
|
||||
.join("repo-personality-workspace");
|
||||
let artifacts = root
|
||||
.join(".epiphany-smoke")
|
||||
.join("repo-personality-artifacts");
|
||||
reset_smoke_path(&root, &workspace)?;
|
||||
reset_smoke_path(&root, &artifacts)?;
|
||||
let cult_repo = create_repo(
|
||||
&workspace.join("CultTiny"),
|
||||
&[
|
||||
(
|
||||
"AGENTS.md",
|
||||
"Prefer typed schemas and tiny public contracts.\n",
|
||||
),
|
||||
("src/lib.rs", "pub fn schema_contract() {}\n"),
|
||||
(
|
||||
"docs/architecture.md",
|
||||
"# Architecture\nCultTiny stores typed contract surfaces.\n",
|
||||
),
|
||||
(
|
||||
"research/prior-art.md",
|
||||
"# Prior Art\nPrefer known schema formats before invention.\n",
|
||||
),
|
||||
(
|
||||
"tests/contract_smoke.rs",
|
||||
"#[test] fn contract_smoke() {}\n",
|
||||
),
|
||||
("schemas/message.schema.json", "{\"type\":\"object\"}\n"),
|
||||
],
|
||||
"Add schema contract smoke",
|
||||
)?;
|
||||
let lore_repo = create_repo(
|
||||
&workspace.join("LoreTiny"),
|
||||
&[
|
||||
(
|
||||
"AGENTS.md",
|
||||
"Respect canon, source notes, and public voice.\n",
|
||||
),
|
||||
("state/map.yaml", "objective: preserve canon\n"),
|
||||
("notes/fresh-workspace-handoff.md", "Read the map first.\n"),
|
||||
("Chronicles/City.md", "# City\nCanon material.\n"),
|
||||
],
|
||||
"Polish canon handoff",
|
||||
)?;
|
||||
|
||||
let scout = run_personality(
|
||||
&root,
|
||||
&[
|
||||
"scout",
|
||||
"--root",
|
||||
workspace.to_str().unwrap_or_default(),
|
||||
"--artifact-dir",
|
||||
artifacts.join("scout").to_str().unwrap_or_default(),
|
||||
],
|
||||
)?;
|
||||
require(scout["repoCount"] == 2, "scout should find two git repos")?;
|
||||
let baseline = path_value(&scout, "store")?;
|
||||
require(baseline.exists(), "scout should write typed baseline store")?;
|
||||
|
||||
let projection = run_personality(
|
||||
&root,
|
||||
&[
|
||||
"project",
|
||||
"--repo",
|
||||
cult_repo.to_str().unwrap_or_default(),
|
||||
"--baseline",
|
||||
baseline.to_str().unwrap_or_default(),
|
||||
"--artifact-dir",
|
||||
artifacts.join("cult-project").to_str().unwrap_or_default(),
|
||||
],
|
||||
)?;
|
||||
require(
|
||||
projection["profile"]["roleProjectionCount"] == 8,
|
||||
"project should emit all standing role projections",
|
||||
)?;
|
||||
let store = path_value(&projection, "store")?;
|
||||
require(
|
||||
store.exists(),
|
||||
"project should write typed projection store",
|
||||
)?;
|
||||
|
||||
let packet = run_personality(
|
||||
&root,
|
||||
&[
|
||||
"agent-packet",
|
||||
"--store",
|
||||
store.to_str().unwrap_or_default(),
|
||||
"--artifact-dir",
|
||||
artifacts.join("cult-packet").to_str().unwrap_or_default(),
|
||||
],
|
||||
)?;
|
||||
require(
|
||||
packet["roleProjectionCount"] == 8,
|
||||
"agent packet should carry eight role projections",
|
||||
)?;
|
||||
let packet_path = path_value(&packet, "packetPath")?;
|
||||
let prompt_path = path_value(&packet, "promptPath")?;
|
||||
let packet_summary_path = path_value(&packet, "summaryPath")?;
|
||||
require(
|
||||
packet_path.exists(),
|
||||
"agent packet should write packet json",
|
||||
)?;
|
||||
require(
|
||||
prompt_path.exists(),
|
||||
"agent packet should write prompt markdown",
|
||||
)?;
|
||||
require(
|
||||
packet_summary_path.exists(),
|
||||
"agent packet should write summary markdown",
|
||||
)?;
|
||||
|
||||
let memory_packet = run_personality(
|
||||
&root,
|
||||
&[
|
||||
"memory-packet",
|
||||
"--store",
|
||||
store.to_str().unwrap_or_default(),
|
||||
"--artifact-dir",
|
||||
artifacts
|
||||
.join("cult-memory-packet")
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
],
|
||||
)?;
|
||||
require(
|
||||
memory_packet["memorySourceCount"].as_u64().unwrap_or(0) > 0,
|
||||
"memory packet should carry source excerpts",
|
||||
)?;
|
||||
require(
|
||||
memory_packet["roleDistillerCount"] == 8,
|
||||
"memory packet should carry all role distiller lanes",
|
||||
)?;
|
||||
let memory_packet_path = path_value(&memory_packet, "packetPath")?;
|
||||
let memory_prompt_path = path_value(&memory_packet, "promptPath")?;
|
||||
let memory_summary_path = path_value(&memory_packet, "summaryPath")?;
|
||||
require(
|
||||
memory_packet_path.exists(),
|
||||
"memory packet should write packet json",
|
||||
)?;
|
||||
require(
|
||||
memory_prompt_path.exists(),
|
||||
"memory packet should write prompt markdown",
|
||||
)?;
|
||||
require(
|
||||
memory_summary_path.exists(),
|
||||
"memory packet should write summary markdown",
|
||||
)?;
|
||||
|
||||
let trajectory_packet = run_personality(
|
||||
&root,
|
||||
&[
|
||||
"trajectory-packet",
|
||||
"--store",
|
||||
store.to_str().unwrap_or_default(),
|
||||
"--artifact-dir",
|
||||
artifacts
|
||||
.join("cult-trajectory-packet")
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
],
|
||||
)?;
|
||||
require(
|
||||
trajectory_packet["trajectoryThemeCount"]
|
||||
.as_u64()
|
||||
.unwrap_or(0)
|
||||
> 0,
|
||||
"trajectory packet should carry trajectory themes",
|
||||
)?;
|
||||
let trajectory_packet_path = path_value(&trajectory_packet, "packetPath")?;
|
||||
let trajectory_prompt_path = path_value(&trajectory_packet, "promptPath")?;
|
||||
let trajectory_summary_path = path_value(&trajectory_packet, "summaryPath")?;
|
||||
require(
|
||||
trajectory_packet_path.exists(),
|
||||
"trajectory packet should write packet json",
|
||||
)?;
|
||||
require(
|
||||
trajectory_prompt_path.exists(),
|
||||
"trajectory packet should write prompt markdown",
|
||||
)?;
|
||||
require(
|
||||
trajectory_summary_path.exists(),
|
||||
"trajectory packet should write summary markdown",
|
||||
)?;
|
||||
|
||||
let init_store = artifacts.join("repo-initialization.msgpack");
|
||||
let startup = run_personality(
|
||||
&root,
|
||||
&[
|
||||
"startup",
|
||||
"--repo",
|
||||
cult_repo.to_str().unwrap_or_default(),
|
||||
"--baseline",
|
||||
baseline.to_str().unwrap_or_default(),
|
||||
"--artifact-dir",
|
||||
artifacts.join("startup-first").to_str().unwrap_or_default(),
|
||||
"--init-store",
|
||||
init_store.to_str().unwrap_or_default(),
|
||||
],
|
||||
)?;
|
||||
require(
|
||||
startup["action"] == "reviewInitializationPackets",
|
||||
"startup should request birth packet review before accepted records exist",
|
||||
)?;
|
||||
require(
|
||||
startup["generatedPackets"].as_array().map_or(0, Vec::len) == 3,
|
||||
"startup should generate trajectory, personality, and memory packets",
|
||||
)?;
|
||||
let startup_trajectory_packet = packet_for_kind(&startup, "repo-trajectory")?;
|
||||
let startup_personality_packet = packet_for_kind(&startup, "repo-personality")?;
|
||||
let startup_memory_packet = packet_for_kind(&startup, "repo-memory")?;
|
||||
require(
|
||||
startup_trajectory_packet.exists(),
|
||||
"startup should write trajectory packet",
|
||||
)?;
|
||||
require(
|
||||
startup_personality_packet.exists(),
|
||||
"startup should write personality packet",
|
||||
)?;
|
||||
require(
|
||||
startup_memory_packet.exists(),
|
||||
"startup should write memory packet",
|
||||
)?;
|
||||
let birth_runner = run_birth_runner(
|
||||
&root,
|
||||
&[
|
||||
"--repo",
|
||||
cult_repo.to_str().unwrap_or_default(),
|
||||
"--baseline",
|
||||
baseline.to_str().unwrap_or_default(),
|
||||
"--artifact-dir",
|
||||
artifacts
|
||||
.join("birth-runner-plan")
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
"--init-store",
|
||||
artifacts
|
||||
.join("birth-runner-plan")
|
||||
.join("repo-initialization.msgpack")
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
"--agent-store",
|
||||
root.join("state")
|
||||
.join("agents.msgpack")
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
"--heartbeat-store",
|
||||
root.join("state")
|
||||
.join("agent-heartbeats.msgpack")
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
"--mode",
|
||||
"plan",
|
||||
],
|
||||
)?;
|
||||
require(
|
||||
birth_runner["schemaVersion"] == "epiphany.repo_birth_runner.v0",
|
||||
"birth runner should return its schema",
|
||||
)?;
|
||||
require(
|
||||
birth_runner["executions"].as_array().map_or(0, Vec::len) == 3,
|
||||
"birth runner plan should expose all startup-only specialist executions",
|
||||
)?;
|
||||
require(
|
||||
birth_runner["executions"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.all(|execution| execution["heartbeatParticipant"].is_null()),
|
||||
"birth runner executions should not be heartbeat participants",
|
||||
)?;
|
||||
let heartbeat_store = artifacts.join("startup-heartbeats.msgpack");
|
||||
run_heartbeat(
|
||||
&root,
|
||||
&[
|
||||
"init",
|
||||
"--store",
|
||||
heartbeat_store.to_str().unwrap_or_default(),
|
||||
],
|
||||
)?;
|
||||
let trajectory_result_path = artifacts.join("startup-trajectory-result.json");
|
||||
fs::write(
|
||||
&trajectory_result_path,
|
||||
serde_json::to_vec_pretty(&json!({
|
||||
"verdict": "ready-for-review",
|
||||
"summary": "Smoke trajectory birth distillation.",
|
||||
"confidence": 0.88,
|
||||
"selfImage": "CultTiny is becoming a typed-contract workspace that prefers receipts to swagger.",
|
||||
"trajectoryNarrative": "The tiny history and docs both lean toward explicit schema boundaries, known formats, and reviewable proof over improvising private protocol sludge.",
|
||||
"implicitGoals": ["Keep future expansion grounded in explicit schemas and receipts."],
|
||||
"antiGoals": ["Do not drift into ad hoc protocol glue just because the fixture is small."],
|
||||
"roleBiases": [{
|
||||
"roleId": "coordinator",
|
||||
"bias": "Self should treat typed-schema growth as part of the repo's grain.",
|
||||
"trajectorySignals": ["systems_formalization", "protocol_intolerance"],
|
||||
"behavioralEffect": "Challenge loose glue early.",
|
||||
"risk": "Could become stiff if later work needs play.",
|
||||
"evidenceRefs": ["AGENTS.md", "docs/architecture.md"]
|
||||
}],
|
||||
"selfPatchCandidates": [{
|
||||
"roleId": "coordinator",
|
||||
"selfPatch": {
|
||||
"agentId": "epiphany.self",
|
||||
"reason": "Trajectory birth should teach Self that CultTiny has been moving toward typed receipts and explicit contracts.",
|
||||
"semanticMemories": [{
|
||||
"memoryId": "mem-self-startup-trajectory-smoke",
|
||||
"summary": "CultTiny's trajectory favors typed contract growth and evidence-backed explicitness over casual glue.",
|
||||
"salience": 0.74,
|
||||
"confidence": 0.87
|
||||
}]
|
||||
}
|
||||
}],
|
||||
"initializationRecord": {
|
||||
"repoId": "culttiny",
|
||||
"distillerKind": "repo-trajectory",
|
||||
"acceptedOnce": true
|
||||
},
|
||||
"doNotMutate": [],
|
||||
"nextSafeMove": "Self reviews the trajectory petition before it colors later memory drift."
|
||||
}))?,
|
||||
)?;
|
||||
let accepted_trajectory = run_personality(
|
||||
&root,
|
||||
&[
|
||||
"accept-init",
|
||||
"--init-store",
|
||||
init_store.to_str().unwrap_or_default(),
|
||||
"--packet",
|
||||
startup_trajectory_packet.to_str().unwrap_or_default(),
|
||||
"--kind",
|
||||
"repo-trajectory",
|
||||
"--accepted-by",
|
||||
"smoke-self",
|
||||
"--summary",
|
||||
"Smoke accepted repo trajectory birth packet after review.",
|
||||
"--result",
|
||||
trajectory_result_path.to_str().unwrap_or_default(),
|
||||
"--agent-store",
|
||||
root.join("state")
|
||||
.join("agents.msgpack")
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
"--apply-self-patches",
|
||||
"false",
|
||||
],
|
||||
)?;
|
||||
require(
|
||||
accepted_trajectory["record"]["kind"] == "repo-trajectory",
|
||||
"accept-init should record trajectory birth",
|
||||
)?;
|
||||
let agent_store = artifacts.join("startup-agents.msgpack");
|
||||
fs::copy(root.join("state").join("agents.msgpack"), &agent_store)
|
||||
.context("failed to copy role memory store for startup smoke")?;
|
||||
let accepted_personality = run_personality(
|
||||
&root,
|
||||
&[
|
||||
"accept-init",
|
||||
"--init-store",
|
||||
init_store.to_str().unwrap_or_default(),
|
||||
"--packet",
|
||||
startup_personality_packet.to_str().unwrap_or_default(),
|
||||
"--kind",
|
||||
"repo-personality",
|
||||
"--accepted-by",
|
||||
"smoke-self",
|
||||
"--summary",
|
||||
"Smoke accepted repo personality birth packet after review.",
|
||||
"--agent-store",
|
||||
agent_store.to_str().unwrap_or_default(),
|
||||
"--apply-trait-seeds",
|
||||
"true",
|
||||
"--heartbeat-store",
|
||||
heartbeat_store.to_str().unwrap_or_default(),
|
||||
"--apply-heartbeat-seeds",
|
||||
"true",
|
||||
],
|
||||
)?;
|
||||
require(
|
||||
accepted_personality["record"]["kind"] == "repo-personality",
|
||||
"accept-init should record personality birth",
|
||||
)?;
|
||||
require(
|
||||
accepted_personality["heartbeatSeeds"]["applied"]
|
||||
.as_u64()
|
||||
.unwrap_or_default()
|
||||
> 0,
|
||||
"accept-init should apply heartbeat seed mutations",
|
||||
)?;
|
||||
require(
|
||||
accepted_personality["traitLatticePersistence"]["applied"]
|
||||
.as_u64()
|
||||
.unwrap_or_default()
|
||||
> 0,
|
||||
"accept-init should stamp newborn canonical trait lattice seeds",
|
||||
)?;
|
||||
let coordinator = load_agent_memory_entry_for_role(&agent_store, "coordinator")?
|
||||
.ok_or_else(|| anyhow!("startup smoke lost coordinator role memory entry"))?;
|
||||
require(
|
||||
!coordinator
|
||||
.agent
|
||||
.canonical_state
|
||||
.underlying_organization
|
||||
.contains_key("baseline"),
|
||||
"personality accept-init should replace baseline canonical traits for coordinator",
|
||||
)?;
|
||||
require(
|
||||
coordinator
|
||||
.agent
|
||||
.canonical_state
|
||||
.underlying_organization
|
||||
.contains_key("routing_discipline"),
|
||||
"personality accept-init should seed coordinator routing_discipline trait",
|
||||
)?;
|
||||
let memory_result_path = artifacts.join("startup-memory-result.json");
|
||||
fs::write(
|
||||
&memory_result_path,
|
||||
serde_json::to_vec_pretty(&json!({
|
||||
"verdict": "ready-for-review",
|
||||
"summary": "Smoke newborn memory distillation.",
|
||||
"confidence": 0.9,
|
||||
"roleMemoryPatches": [{
|
||||
"roleId": "modeling",
|
||||
"roleName": "Modeling",
|
||||
"verdict": "ready-for-review",
|
||||
"selfPatch": {
|
||||
"agentId": "epiphany.modeling",
|
||||
"reason": "Birth memory should teach Modeling that repo initialization memory is reviewed and typed.",
|
||||
"semanticMemories": [{
|
||||
"memoryId": "mem-body-startup-birth-memory-smoke",
|
||||
"summary": "Repo memory birth packets can produce role-specific selfPatch candidates that are applied only after Self review.",
|
||||
"salience": 0.72,
|
||||
"confidence": 0.88
|
||||
}]
|
||||
},
|
||||
"sourceRefs": ["AGENTS.md"],
|
||||
"whyThisBelongsInMemory": "Modeling needs the startup memory route to stay source-grounded.",
|
||||
"stalenessRisk": "smoke fixture",
|
||||
"doNotStore": []
|
||||
}]
|
||||
}))?,
|
||||
)?;
|
||||
let accepted_memory = run_personality(
|
||||
&root,
|
||||
&[
|
||||
"accept-init",
|
||||
"--init-store",
|
||||
init_store.to_str().unwrap_or_default(),
|
||||
"--packet",
|
||||
startup_memory_packet.to_str().unwrap_or_default(),
|
||||
"--kind",
|
||||
"repo-memory",
|
||||
"--accepted-by",
|
||||
"smoke-self",
|
||||
"--summary",
|
||||
"Smoke accepted repo memory birth packet after review.",
|
||||
"--result",
|
||||
memory_result_path.to_str().unwrap_or_default(),
|
||||
"--agent-store",
|
||||
agent_store.to_str().unwrap_or_default(),
|
||||
"--apply-self-patches",
|
||||
"true",
|
||||
],
|
||||
)?;
|
||||
require(
|
||||
accepted_memory["record"]["kind"] == "repo-memory",
|
||||
"accept-init should record memory birth",
|
||||
)?;
|
||||
require(
|
||||
accepted_memory["selfPersistence"]["applied"] == 1,
|
||||
"accept-init should apply reviewed memory selfPatch candidates",
|
||||
)?;
|
||||
let startup_after_accept = run_personality(
|
||||
&root,
|
||||
&[
|
||||
"startup",
|
||||
"--repo",
|
||||
cult_repo.to_str().unwrap_or_default(),
|
||||
"--baseline",
|
||||
baseline.to_str().unwrap_or_default(),
|
||||
"--artifact-dir",
|
||||
artifacts
|
||||
.join("startup-after-accept")
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
"--init-store",
|
||||
init_store.to_str().unwrap_or_default(),
|
||||
],
|
||||
)?;
|
||||
require(
|
||||
startup_after_accept["action"] == "continueStartup",
|
||||
"startup should not rerun birth packets after accepted records exist",
|
||||
)?;
|
||||
require(
|
||||
startup_after_accept["generatedPackets"]
|
||||
.as_array()
|
||||
.is_some_and(Vec::is_empty),
|
||||
"startup should generate no packets after accepted records exist",
|
||||
)?;
|
||||
|
||||
let status = run_personality(
|
||||
&root,
|
||||
&["status", "--store", store.to_str().unwrap_or_default()],
|
||||
)?;
|
||||
require(
|
||||
status["reports"] == 1,
|
||||
"projection store should have one report",
|
||||
)?;
|
||||
require(
|
||||
status["profiles"] == 1,
|
||||
"projection store should have one profile",
|
||||
)?;
|
||||
require(
|
||||
status["trajectoryReports"] == 1,
|
||||
"projection store should have one trajectory report",
|
||||
)?;
|
||||
require(
|
||||
status["roleProjections"] == 8,
|
||||
"projection store should have eight role projections",
|
||||
)?;
|
||||
|
||||
Ok(json!({
|
||||
"workspace": workspace,
|
||||
"artifactRoot": artifacts,
|
||||
"cultRepo": cult_repo,
|
||||
"loreRepo": lore_repo,
|
||||
"baseline": baseline,
|
||||
"projectionStore": store,
|
||||
"packetPath": packet_path,
|
||||
"promptPath": prompt_path,
|
||||
"packetSummaryPath": packet_summary_path,
|
||||
"trajectoryPacketPath": trajectory_packet_path,
|
||||
"trajectoryPromptPath": trajectory_prompt_path,
|
||||
"trajectorySummaryPath": trajectory_summary_path,
|
||||
"memoryPacketPath": memory_packet_path,
|
||||
"memoryPromptPath": memory_prompt_path,
|
||||
"memorySummaryPath": memory_summary_path,
|
||||
"initStore": init_store,
|
||||
"agentStore": agent_store,
|
||||
"heartbeatStore": heartbeat_store,
|
||||
"birthRunnerSummary": artifacts.join("birth-runner-plan").join("birth-runner-summary.json"),
|
||||
"startupTrajectoryPacket": startup_trajectory_packet,
|
||||
"startupPersonalityPacket": startup_personality_packet,
|
||||
"startupMemoryPacket": startup_memory_packet,
|
||||
"startupTrajectoryResult": trajectory_result_path,
|
||||
"startupMemoryResult": memory_result_path,
|
||||
"startupAfterAcceptAction": startup_after_accept["action"],
|
||||
"repoCount": scout["repoCount"],
|
||||
"trajectoryReports": status["trajectoryReports"],
|
||||
"roleProjections": status["roleProjections"],
|
||||
}))
|
||||
}
|
||||
|
||||
fn create_repo(root: &Path, files: &[(&str, &str)], commit_message: &str) -> Result<PathBuf> {
|
||||
fs::create_dir_all(root)?;
|
||||
run_git(root, &["init"])?;
|
||||
run_git(
|
||||
root,
|
||||
&["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
)?;
|
||||
run_git(root, &["config", "user.name", "Epiphany Smoke"])?;
|
||||
for (path, content) in files {
|
||||
let path = root.join(path);
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
fs::write(path, content)?;
|
||||
}
|
||||
run_git(root, &["add", "."])?;
|
||||
run_git(root, &["commit", "-m", commit_message])?;
|
||||
Ok(root.to_path_buf())
|
||||
}
|
||||
|
||||
fn run_personality(root: &Path, args: &[&str]) -> Result<Value> {
|
||||
let exe = native_personality_exe()?;
|
||||
ensure_built(root, "epiphany-repo-personality", &exe)?;
|
||||
let output = Command::new(exe)
|
||||
.current_dir(root)
|
||||
.args(args)
|
||||
.output()
|
||||
.context("failed to run epiphany-repo-personality")?;
|
||||
require(
|
||||
output.status.success(),
|
||||
&format!(
|
||||
"epiphany-repo-personality failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
),
|
||||
)?;
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"epiphany-repo-personality did not return JSON: {}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn run_birth_runner(root: &Path, args: &[&str]) -> Result<Value> {
|
||||
let exe = native_birth_runner_exe()?;
|
||||
ensure_built(root, "epiphany-repo-birth-runner", &exe)?;
|
||||
let output = Command::new(exe)
|
||||
.current_dir(root)
|
||||
.args(args)
|
||||
.output()
|
||||
.context("failed to run epiphany-repo-birth-runner")?;
|
||||
require(
|
||||
output.status.success(),
|
||||
&format!(
|
||||
"epiphany-repo-birth-runner failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
),
|
||||
)?;
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"epiphany-repo-birth-runner did not return JSON: {}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn run_heartbeat(root: &Path, args: &[&str]) -> Result<Value> {
|
||||
let exe = native_heartbeat_exe()?;
|
||||
ensure_built(root, "epiphany-heartbeat-store", &exe)?;
|
||||
let output = Command::new(exe)
|
||||
.current_dir(root)
|
||||
.args(args)
|
||||
.output()
|
||||
.context("failed to run epiphany-heartbeat-store")?;
|
||||
require(
|
||||
output.status.success(),
|
||||
&format!(
|
||||
"epiphany-heartbeat-store failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
),
|
||||
)?;
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"epiphany-heartbeat-store did not return JSON: {}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn native_personality_exe() -> Result<PathBuf> {
|
||||
let target_dir = env::var_os("CARGO_TARGET_DIR")
|
||||
.unwrap_or_else(|| r"C:\Users\Meta\.cargo-target-codex".into());
|
||||
Ok(PathBuf::from(target_dir).join("debug").join(format!(
|
||||
"epiphany-repo-personality{}",
|
||||
env::consts::EXE_SUFFIX
|
||||
)))
|
||||
}
|
||||
|
||||
fn native_birth_runner_exe() -> Result<PathBuf> {
|
||||
let target_dir = env::var_os("CARGO_TARGET_DIR")
|
||||
.unwrap_or_else(|| r"C:\Users\Meta\.cargo-target-codex".into());
|
||||
Ok(PathBuf::from(target_dir).join("debug").join(format!(
|
||||
"epiphany-repo-birth-runner{}",
|
||||
env::consts::EXE_SUFFIX
|
||||
)))
|
||||
}
|
||||
|
||||
fn native_heartbeat_exe() -> Result<PathBuf> {
|
||||
let target_dir = env::var_os("CARGO_TARGET_DIR")
|
||||
.unwrap_or_else(|| r"C:\Users\Meta\.cargo-target-codex".into());
|
||||
Ok(PathBuf::from(target_dir).join("debug").join(format!(
|
||||
"epiphany-heartbeat-store{}",
|
||||
env::consts::EXE_SUFFIX
|
||||
)))
|
||||
}
|
||||
|
||||
fn ensure_built(root: &Path, bin: &str, exe: &Path) -> Result<()> {
|
||||
let status = Command::new("cargo")
|
||||
.current_dir(root)
|
||||
.arg("build")
|
||||
.arg("--manifest-path")
|
||||
.arg(root.join("epiphany-core").join("Cargo.toml"))
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.status()
|
||||
.with_context(|| format!("failed to build {bin}"))?;
|
||||
require(
|
||||
status.success() && exe.exists(),
|
||||
&format!("{bin} executable was not built at {}", exe.display()),
|
||||
)
|
||||
}
|
||||
|
||||
fn run_git(repo: &Path, args: &[&str]) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.current_dir(repo)
|
||||
.args(args)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git {}", args.join(" ")))?;
|
||||
require(
|
||||
output.status.success(),
|
||||
&format!(
|
||||
"git {} failed: {}",
|
||||
args.join(" "),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn reset_smoke_path(root: &Path, path: &Path) -> Result<()> {
|
||||
let quarantine = root.join(".epiphany-smoke");
|
||||
fs::create_dir_all(&quarantine)?;
|
||||
let quarantine = quarantine.canonicalize()?;
|
||||
let parent = path.parent().unwrap_or_else(|| Path::new("."));
|
||||
fs::create_dir_all(parent)?;
|
||||
let resolved = if path.exists() {
|
||||
path.canonicalize()?
|
||||
} else {
|
||||
parent.canonicalize()?.join(
|
||||
path.file_name()
|
||||
.ok_or_else(|| anyhow!("smoke path has no leaf"))?,
|
||||
)
|
||||
};
|
||||
if resolved == quarantine || !resolved.starts_with(&quarantine) {
|
||||
return Err(anyhow!(
|
||||
"refusing to reset path outside smoke quarantine: {}",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
if path.exists() {
|
||||
fs::remove_dir_all(path).with_context(|| format!("failed to reset {}", path.display()))?;
|
||||
}
|
||||
fs::create_dir_all(path).with_context(|| format!("failed to create {}", path.display()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod reset_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn reset_refuses_traversal_outside_smoke_quarantine() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
let escaped = temp.path().join(".epiphany-smoke").join("..");
|
||||
let error = reset_smoke_path(temp.path(), &escaped).expect_err("escape must fail");
|
||||
assert!(error.to_string().contains("outside smoke quarantine"));
|
||||
assert!(temp.path().exists());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn path_value(value: &Value, key: &str) -> Result<PathBuf> {
|
||||
value
|
||||
.get(key)
|
||||
.and_then(Value::as_str)
|
||||
.map(PathBuf::from)
|
||||
.ok_or_else(|| anyhow!("missing path value {key}"))
|
||||
}
|
||||
|
||||
fn packet_for_kind(value: &Value, kind: &str) -> Result<PathBuf> {
|
||||
value["generatedPackets"]
|
||||
.as_array()
|
||||
.and_then(|packets| {
|
||||
packets
|
||||
.iter()
|
||||
.find(|packet| packet["kind"] == kind)
|
||||
.and_then(|packet| packet["packetPath"].as_str())
|
||||
})
|
||||
.map(PathBuf::from)
|
||||
.ok_or_else(|| anyhow!("missing generated packet for {kind}"))
|
||||
}
|
||||
|
||||
fn require(condition: bool, message: &str) -> Result<()> {
|
||||
if condition {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(message.to_string()))
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,443 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-pr-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo PR Request Family Smoke\n\nThis repository proves branch-local PR request cargo without GitHub PR authority.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(["commit", "-m", "Seed repo PR request smoke body"], &repo)?;
|
||||
git(["switch", "-c", "epiphany/repo-pr-request-family"], &repo)?;
|
||||
|
||||
let item = "repo-pr-request-family";
|
||||
let target_path = ".epiphany/pr-requests/repo-pr-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-pr-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-pr-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-pr-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask Bifrost and GitHub to prepare a review PR packet without granting push, PR, or merge authority.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-pr-request-family/pr-packet",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-pr-request-family/github-review",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-pr-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-pr-request",
|
||||
"--model-ref",
|
||||
"repo-pr-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.pr_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_pr_request.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "safe_action_family = \"repo.pr_request\"")?;
|
||||
require_text(&request_text, "[request]")?;
|
||||
require_text(&request_text, "status = \"awaiting-pr-publication-review\"")?;
|
||||
require_text(&request_text, "routing_owner = \"Self\"")?;
|
||||
require_text(&request_text, "publication_owner = \"Bifrost\"")?;
|
||||
require_text(&request_text, "execution_owner = \"Hands\"")?;
|
||||
require_text(&request_text, "provider = \"GitHub\"")?;
|
||||
require_text(&request_text, "provider_receipt_required = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requested_effect = \"open-or-update-review-pr-from-redacted-proof-and-maintainer-context\"",
|
||||
)?;
|
||||
require_text(&request_text, "maintainer_review_request_ref = ")?;
|
||||
require_text(&request_text, "publication_request_ref = ")?;
|
||||
require_text(&request_text, "sync_request_ref = ")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"pr_scope = \"branch diff, redacted public proof, maintainer review, Bifrost credit context, and upstream-main follow-up\"",
|
||||
)?;
|
||||
require_text(&request_text, "[antecedents]")?;
|
||||
require_text(&request_text, "closure_review_required = true")?;
|
||||
require_text(&request_text, "soul_verdict_required = true")?;
|
||||
require_text(&request_text, "mind_commit_required = true")?;
|
||||
require_text(&request_text, "public_proof_required = true")?;
|
||||
require_text(&request_text, "maintainer_review_required = true")?;
|
||||
require_text(&request_text, "bifrost_publication_required = true")?;
|
||||
require_text(&request_text, "credit_ledger_required = true")?;
|
||||
require_text(&request_text, "[required_receipts]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"closure_review = \"epiphany.repo_work_closure_review.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"soul_verdict = \"epiphany.soul.verification_verdict\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"mind_commit = \"epiphany.mind.state_commit_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"public_proof = \"epiphany.repo_work_public_proof_bundle.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"maintainer_review = \"gamecult.maintainer.review_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"bifrost_publication = \"gamecult.bifrost.public_proof_publication_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"credit_ledger = \"gamecult.bifrost.credit_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"pr_publication = \"gamecult.github.pull_request_publication_receipt.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "[pr_packet]")?;
|
||||
require_text(&request_text, "base_ref = \"origin/main\"")?;
|
||||
require_text(&request_text, "requires_branch_name = true")?;
|
||||
require_text(&request_text, "requires_title = true")?;
|
||||
require_text(&request_text, "requires_body = true")?;
|
||||
require_text(&request_text, "requires_changed_path_list = true")?;
|
||||
require_text(&request_text, "requires_public_proof_ref = true")?;
|
||||
require_text(&request_text, "requires_maintainer_review_ref = true")?;
|
||||
require_text(&request_text, "requires_credit_ref = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requires_private_state_redaction_check = true",
|
||||
)?;
|
||||
require_text(&request_text, "github_pr_authorized = false")?;
|
||||
require_text(&request_text, "branch_push_authorized = false")?;
|
||||
require_text(&request_text, "merge_authorized = false")?;
|
||||
require_text(&request_text, "publication_authorized = false")?;
|
||||
require_text(&request_text, "upstream_sync_authorized = false")?;
|
||||
require_text(&request_text, "hands_action_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "maintainer_review_required = true")?;
|
||||
require_text(&request_text, "bifrost_publication_gate_required = true")?;
|
||||
require_text(&request_text, "hands_execution_required = true")?;
|
||||
require_text(&request_text, "github_provider_receipt_required = true")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_pr_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingPrPublicationReview": true,
|
||||
"githubPrAuthorized": false,
|
||||
"branchPushAuthorized": false,
|
||||
"mergeAuthorized": false,
|
||||
"publicationAuthorized": false,
|
||||
"upstreamSyncAuthorized": false,
|
||||
"handsActionAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("expected PR request text to contain {needle:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,435 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-publication-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Publication Request Family Smoke\n\nThis repository proves branch-local Hands publication-request requests.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed repo publication request smoke body"],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
["switch", "-c", "epiphany/repo-publication-request-family"],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-publication-request-family";
|
||||
let target_path = ".epiphany/publication-requests/repo-publication-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-publication-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-publication-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-publication-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask Bifrost to review redacted public proof after Soul and Mind receipts exist.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-publication-request-family/bifrost-review",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-publication-request-family/redacted-proof-publication",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-publication-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-publication-request",
|
||||
"--model-ref",
|
||||
"repo-publication-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.publication_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_publication_request.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"safe_action_family = \"repo.publication_request\"",
|
||||
)?;
|
||||
require_text(&request_text, "[request]")?;
|
||||
require_text(&request_text, "status = \"awaiting-bifrost-review\"")?;
|
||||
require_text(&request_text, "requested_owner = \"Bifrost\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requested_effect = \"publish-redacted-proof-and-route-maintainer-review\"",
|
||||
)?;
|
||||
require_text(&request_text, "verification_request_ref = ")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"publication_scope = \"redacted public proof, maintainer review, credit ledger, and upstream-main sync proof\"",
|
||||
)?;
|
||||
require_text(&request_text, "[antecedents]")?;
|
||||
require_text(&request_text, "closure_review_required = true")?;
|
||||
require_text(&request_text, "soul_verdict_required = true")?;
|
||||
require_text(&request_text, "mind_commit_required = true")?;
|
||||
require_text(&request_text, "public_proof_export_required = true")?;
|
||||
require_text(&request_text, "private_state_redaction_required = true")?;
|
||||
require_text(&request_text, "[required_receipts]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"closure_review = \"epiphany.repo_work_closure_review.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"soul_verdict = \"epiphany.soul.verification_verdict\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"mind_commit = \"epiphany.mind.state_commit_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"public_proof = \"epiphany.repo_work_public_proof_bundle.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"bifrost_publication = \"gamecult.bifrost.public_proof_publication_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"github_publication = \"gamecult.github.publication_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"credit_ledger = \"gamecult.bifrost.credit_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"upstream_sync = \"epiphany.repo_work_upstream_main_sync.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "[public_export]")?;
|
||||
require_text(&request_text, "redacted_only = true")?;
|
||||
require_text(&request_text, "raw_receipts_allowed = false")?;
|
||||
require_text(&request_text, "private_paths_allowed = false")?;
|
||||
require_text(&request_text, "worker_thought_allowed = false")?;
|
||||
require_text(&request_text, "operator_context_allowed = false")?;
|
||||
require_text(&request_text, "credit_required = true")?;
|
||||
require_text(&request_text, "bifrost_publication_authorized = false")?;
|
||||
require_text(&request_text, "github_publication_authorized = false")?;
|
||||
require_text(&request_text, "credit_ledger_authorized = false")?;
|
||||
require_text(&request_text, "merge_authorized = false")?;
|
||||
require_text(&request_text, "upstream_sync_authorized = false")?;
|
||||
require_text(&request_text, "hands_action_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_publication_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingBifrostReview": true,
|
||||
"bifrostPublicationAuthorized": false,
|
||||
"githubPublicationAuthorized": false,
|
||||
"creditLedgerAuthorized": false,
|
||||
"upstreamSyncAuthorized": false,
|
||||
"handsActionAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected publication request text to contain {needle:?}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,520 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-readiness-review-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Readiness Review Request Family Smoke\n\nThis repository proves branch-local MVP readiness review request cargo without publication, merge, deployment, service, or state authority.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(
|
||||
[
|
||||
"commit",
|
||||
"-m",
|
||||
"Seed repo readiness review request smoke body",
|
||||
],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
[
|
||||
"switch",
|
||||
"-c",
|
||||
"epiphany/repo-readiness-review-request-family",
|
||||
],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-readiness-review-request-family";
|
||||
let target_path = ".epiphany/readiness-reviews/repo-readiness-review-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-readiness-review-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-readiness-review-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-readiness-review-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask Maintainer, Soul, Mind, and Bifrost to review a redacted repo-swarm MVP proof bundle without granting publication or deployment authority.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-readiness-review-request-family/readiness-packet",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-readiness-review-request-family/proof-bundle-review",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-readiness-review-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-readiness-review-request",
|
||||
"--model-ref",
|
||||
"repo-readiness-review-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.readiness_review_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_readiness_review_request.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"safe_action_family = \"repo.readiness_review_request\"",
|
||||
)?;
|
||||
require_text(&request_text, "[request]")?;
|
||||
require_text(&request_text, "status = \"awaiting-mvp-readiness-review\"")?;
|
||||
require_text(&request_text, "routing_owner = \"Self\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"required_reviewers = [\"Maintainer\", \"Soul\", \"Mind\", \"Bifrost\"]",
|
||||
)?;
|
||||
require_text(&request_text, "readiness_approval_owner = \"Maintainer\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requested_effect = \"review-redacted-repo-swarm-mvp-proof-bundle\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"readiness_scope = \"fresh repo init, online swarm, Persona intake, Imagination planning, Self queue-run, Hands branch work, Soul closure, Modeling map update, Mind admission, Bifrost public proof, upstream-main sync, Idunn lifecycle, global tool directory, and private-state redaction\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"maintainer_readiness_acceptance_required = true",
|
||||
)?;
|
||||
require_text(&request_text, "[antecedents]")?;
|
||||
require_text(&request_text, "repo_init_required = true")?;
|
||||
require_text(&request_text, "swarm_online_required = true")?;
|
||||
require_text(&request_text, "persona_intake_required = true")?;
|
||||
require_text(&request_text, "imagination_plan_required = true")?;
|
||||
require_text(&request_text, "self_queue_run_required = true")?;
|
||||
require_text(&request_text, "hands_commit_required = true")?;
|
||||
require_text(&request_text, "soul_closure_required = true")?;
|
||||
require_text(&request_text, "modeling_map_update_required = true")?;
|
||||
require_text(&request_text, "mind_admission_required = true")?;
|
||||
require_text(&request_text, "public_proof_required = true")?;
|
||||
require_text(&request_text, "bifrost_publication_required = true")?;
|
||||
require_text(&request_text, "upstream_main_sync_required = true")?;
|
||||
require_text(&request_text, "idunn_lifecycle_readiness_required = true")?;
|
||||
require_text(&request_text, "tool_directory_readiness_required = true")?;
|
||||
require_text(&request_text, "private_state_redaction_required = true")?;
|
||||
require_text(&request_text, "[required_receipts]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"repo_init = \"epiphany.repo_swarm_init_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"swarm_online = \"epiphany.repo_swarm_online_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"persona_speech_audit = \"epiphany.persona_speech_audit.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"imagination_action_items = \"epiphany.repo_work_imagination_action_items_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"queue_run = \"epiphany.repo_work_queue_run_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"hands_commit = \"epiphany.hands.commit_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"closure_review = \"epiphany.repo_work_closure_review.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"soul_verdict = \"epiphany.soul.verification_verdict\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"mind_commit = \"epiphany.mind.state_commit_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"public_proof = \"epiphany.repo_work_public_proof_bundle.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"modeling_map = \"epiphany.repo_work_map_entry.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"bifrost_publication = \"gamecult.bifrost.public_proof_publication_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"upstream_sync = \"epiphany.repo_work_upstream_sync_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"idunn_lifecycle = \"epiphany.cultmesh.daemon_service_lifecycle_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"tool_directory = \"epiphany.cultmesh.daemon_tool_directory_readback.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "[readiness_packet]")?;
|
||||
require_text(&request_text, "requires_proof_bundle_ref = true")?;
|
||||
require_text(&request_text, "requires_changed_path_list = true")?;
|
||||
require_text(&request_text, "requires_branch_name = true")?;
|
||||
require_text(&request_text, "requires_upstream_main_ref = true")?;
|
||||
require_text(&request_text, "requires_public_proof_ref = true")?;
|
||||
require_text(&request_text, "requires_bifrost_ledger_ref = true")?;
|
||||
require_text(&request_text, "requires_idunn_lifecycle_ref = true")?;
|
||||
require_text(&request_text, "requires_tool_directory_ref = true")?;
|
||||
require_text(&request_text, "requires_redaction_report = true")?;
|
||||
require_text(&request_text, "requires_reviewer_identity = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"allowed_verdicts = [\"ready\", \"ready-with-caveats\", \"not-ready\", \"needs-human-review\"]",
|
||||
)?;
|
||||
require_text(&request_text, "readiness_approval_authorized = false")?;
|
||||
require_text(&request_text, "durable_state_commit_authorized = false")?;
|
||||
require_text(&request_text, "publication_authorized = false")?;
|
||||
require_text(&request_text, "bifrost_publication_authorized = false")?;
|
||||
require_text(&request_text, "github_pr_authorized = false")?;
|
||||
require_text(&request_text, "merge_authorized = false")?;
|
||||
require_text(&request_text, "upstream_sync_authorized = false")?;
|
||||
require_text(&request_text, "deployment_authority = false")?;
|
||||
require_text(&request_text, "service_lifecycle_authority = false")?;
|
||||
require_text(&request_text, "hands_action_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "private_verse_rummaging = false")?;
|
||||
require_text(&request_text, "maintainer_review_required = true")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_readiness_review_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingMvpReadinessReview": true,
|
||||
"repoInitRequired": true,
|
||||
"swarmOnlineRequired": true,
|
||||
"personaIntakeRequired": true,
|
||||
"imaginationPlanRequired": true,
|
||||
"selfQueueRunRequired": true,
|
||||
"handsCommitRequired": true,
|
||||
"soulClosureRequired": true,
|
||||
"modelingMapUpdateRequired": true,
|
||||
"mindAdmissionRequired": true,
|
||||
"bifrostPublicationRequired": true,
|
||||
"upstreamMainSyncRequired": true,
|
||||
"idunnLifecycleRequired": true,
|
||||
"toolDirectoryRequired": true,
|
||||
"readinessApprovalAuthorized": false,
|
||||
"durableStateCommitAuthorized": false,
|
||||
"githubPrAuthorized": false,
|
||||
"mergeAuthorized": false,
|
||||
"publicationAuthorized": false,
|
||||
"deploymentAuthority": false,
|
||||
"serviceLifecycleAuthority": false,
|
||||
"upstreamSyncAuthorized": false,
|
||||
"handsActionAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected readiness review request text to contain {needle:?}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,403 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-scheduling-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Scheduling Request Family Smoke\n\nThis repository proves branch-local Self scheduling requests.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed repo scheduling request smoke body"],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
["switch", "-c", "epiphany/repo-scheduling-request-family"],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-scheduling-request-family";
|
||||
let target_path = ".epiphany/scheduling-requests/repo-scheduling-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-scheduling-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-scheduling-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-scheduling-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask Self to prepare queue scheduling only after Mind adopts the Objective Draft.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-scheduling-request-family/queue-after-adoption",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-scheduling-request-family/bounded-self-pulse",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-scheduling-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-scheduling-request",
|
||||
"--model-ref",
|
||||
"repo-scheduling-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.scheduling_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_scheduling_request.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"safe_action_family = \"repo.scheduling_request\"",
|
||||
)?;
|
||||
require_text(&request_text, "[request]")?;
|
||||
require_text(&request_text, "status = \"awaiting-mind-adoption\"")?;
|
||||
require_text(&request_text, "requested_scheduler = \"Self\"")?;
|
||||
require_text(&request_text, "mind_adoption_receipt_required = true")?;
|
||||
require_text(&request_text, "self_may_schedule_after_mind_only = true")?;
|
||||
require_text(&request_text, "queue_run_allowed_after_adoption = true")?;
|
||||
require_text(&request_text, "[queue]")?;
|
||||
require_text(&request_text, "target_gate = \"repo-work-queue\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"preferred_next_safe_family = \"repo.task_card\"",
|
||||
)?;
|
||||
require_text(&request_text, "max_items_per_pulse = 1")?;
|
||||
require_text(&request_text, "requires_epiphany_branch = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"publish_blocker = \"bifrost-publication-missing\"",
|
||||
)?;
|
||||
require_text(&request_text, "[required_receipts]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"mind_review = \"epiphany.mind.gateway_review\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"mind_commit = \"epiphany.mind.state_commit_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"expected_self_receipt = \"epiphany.repo_work_queue_selection.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "self_scheduling_authorized = false")?;
|
||||
require_text(&request_text, "queue_mutation_authorized = false")?;
|
||||
require_text(&request_text, "hands_action_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_work_scheduling_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingMindAdoption": true,
|
||||
"queueMutationAuthorized": false,
|
||||
"selfSchedulingAuthorized": false,
|
||||
"handsActionAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected scheduling request text to contain {needle:?}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,416 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-secret-policy-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Secret Policy Request Family Smoke\n\nThis repository proves branch-local secret policy request cargo without secret access.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
fs::write(
|
||||
repo.join(".env.example"),
|
||||
"API_TOKEN=example-only-no-secret-value\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join(".env.example").display()))?;
|
||||
git(["add", "README.md", ".env.example"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed repo secret policy smoke body"],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
["switch", "-c", "epiphany/repo-secret-policy-request-family"],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-secret-policy-request-family";
|
||||
let target_path =
|
||||
".epiphany/security/secret-policy-requests/repo-secret-policy-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-secret-policy-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-secret-policy-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-secret-policy-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask for a reviewed repo secret and write-permission policy without exposing secret values.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-secret-policy-request-family/security-review",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-secret-policy-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-secret-policy-request",
|
||||
"--model-ref",
|
||||
"repo-secret-policy-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
|
||||
let close = read_json(
|
||||
&repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json")),
|
||||
)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
let env_example_text = fs::read_to_string(repo.join(".env.example"))
|
||||
.with_context(|| format!("failed to read {}", repo.join(".env.example").display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.secret_policy_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_secret_policy_request.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"safe_action_family = \"repo.secret_policy_request\"",
|
||||
)?;
|
||||
require_text(&request_text, "status = \"awaiting-security-review\"")?;
|
||||
require_text(&request_text, "routing_owner = \"Self\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requires_secret_inventory_without_values = true",
|
||||
)?;
|
||||
require_text(&request_text, "requires_write_permission_scope = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requires_public_private_export_boundary = true",
|
||||
)?;
|
||||
require_text(&request_text, "source_grounding_required = true")?;
|
||||
require_text(&request_text, "bifrost_publication_review_required = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"source_grounding = \"epiphany.eyes.evidence_packet\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requires_secret_locations_without_values = true",
|
||||
)?;
|
||||
require_text(&request_text, "requires_credential_owner = true")?;
|
||||
require_text(&request_text, "requires_write_scope_matrix = true")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requires_public_export_redaction_rules = true",
|
||||
)?;
|
||||
require_text(&request_text, "requires_deployment_authority_owner = true")?;
|
||||
require_text(&request_text, "requires_incident_rollback_plan = true")?;
|
||||
require_text(&request_text, "direct_secret_access_authority = false")?;
|
||||
require_text(&request_text, "secret_value_materialization = false")?;
|
||||
require_text(&request_text, "write_permission_authority = false")?;
|
||||
require_text(&request_text, "deployment_authority = false")?;
|
||||
require_text(&request_text, "publication_authorized = false")?;
|
||||
require_text(&request_text, "service_lifecycle_authority = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "private_verse_rummaging = false")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
require_text(&env_example_text, "example-only-no-secret-value")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_secret_policy_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingSecurityReview": true,
|
||||
"secretAccessAuthorized": false,
|
||||
"writePermissionAuthorized": false,
|
||||
"deploymentAuthority": false,
|
||||
"publicationAuthorized": false,
|
||||
"serviceLifecycleAuthority": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected secret policy request text to contain {needle:?}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,418 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-sync-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Sync Request Family Smoke\n\nThis repository proves branch-local Hands sync-request requests.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(["commit", "-m", "Seed repo sync request smoke body"], &repo)?;
|
||||
git(["switch", "-c", "epiphany/repo-sync-request-family"], &repo)?;
|
||||
|
||||
let item = "repo-sync-request-family";
|
||||
let target_path = ".epiphany/sync-requests/repo-sync-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-sync-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-sync-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-sync-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask Bifrost to prove the published commit is contained by upstream main after maintainer review.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-sync-request-family/upstream-main-proof",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-sync-request-family/ancestry-proof",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-sync-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-sync-request",
|
||||
"--model-ref",
|
||||
"repo-sync-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.sync_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_sync_request.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "safe_action_family = \"repo.sync_request\"")?;
|
||||
require_text(&request_text, "[request]")?;
|
||||
require_text(&request_text, "status = \"awaiting-upstream-main-proof\"")?;
|
||||
require_text(&request_text, "proof_owner = \"Bifrost\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requested_effect = \"prove-published-commit-contained-by-upstream-main\"",
|
||||
)?;
|
||||
require_text(&request_text, "publication_request_ref = ")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"sync_scope = \"prove maintainer-reviewed published commit is contained by upstream main\"",
|
||||
)?;
|
||||
require_text(&request_text, "[antecedents]")?;
|
||||
require_text(&request_text, "publication_receipt_required = true")?;
|
||||
require_text(&request_text, "github_publication_required = true")?;
|
||||
require_text(&request_text, "maintainer_review_required = true")?;
|
||||
require_text(&request_text, "credit_ledger_required = true")?;
|
||||
require_text(&request_text, "public_proof_required = true")?;
|
||||
require_text(&request_text, "[required_receipts]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"bifrost_publication = \"gamecult.bifrost.public_proof_publication_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"github_publication = \"gamecult.github.publication_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"maintainer_review = \"gamecult.maintainer.review_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"credit_ledger = \"gamecult.bifrost.credit_receipt.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"upstream_sync = \"epiphany.repo_work_upstream_main_sync.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"ancestry_proof = \"git.merge_base_is_ancestor\"",
|
||||
)?;
|
||||
require_text(&request_text, "[sync_proof]")?;
|
||||
require_text(&request_text, "target_ref = \"origin/main\"")?;
|
||||
require_text(&request_text, "requires_fetch_before_check = true")?;
|
||||
require_text(&request_text, "requires_merge_base_ancestor_check = true")?;
|
||||
require_text(&request_text, "requires_clean_public_proof_readback = true")?;
|
||||
require_text(&request_text, "records_upstream_main_sha = true")?;
|
||||
require_text(&request_text, "merge_authorized = false")?;
|
||||
require_text(&request_text, "push_authorized = false")?;
|
||||
require_text(&request_text, "upstream_sync_authorized = false")?;
|
||||
require_text(&request_text, "github_publication_authorized = false")?;
|
||||
require_text(&request_text, "credit_ledger_authorized = false")?;
|
||||
require_text(&request_text, "hands_action_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "bifrost_upstream_proof_required = true")?;
|
||||
require_text(&request_text, "maintainer_review_receipt_required = true")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_sync_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingUpstreamMainProof": true,
|
||||
"mergeAuthorized": false,
|
||||
"pushAuthorized": false,
|
||||
"githubPublicationAuthorized": false,
|
||||
"creditLedgerAuthorized": false,
|
||||
"upstreamSyncAuthorized": false,
|
||||
"handsActionAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("expected sync request text to contain {needle:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,401 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-tool-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Tool Request Family Smoke\n\nThis repository proves branch-local Epiphany daemon tool request cargo.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(["commit", "-m", "Seed repo tool request smoke body"], &repo)?;
|
||||
git(["switch", "-c", "epiphany/repo-tool-request-family"], &repo)?;
|
||||
|
||||
let item = "repo-tool-request-family";
|
||||
let target_path = ".epiphany/tool-requests/repo-tool-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-tool-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-tool-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-tool-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Request a daemon-hosted tool through CultMesh typed intent and receipt contracts without granting direct execution authority.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-tool-request-family/daemon-intent",
|
||||
"--public-discussion-ref",
|
||||
"eve://epiphany/persona/repo-tool-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-tool-request",
|
||||
"--model-ref",
|
||||
"repo-tool-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.tool_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_tool_request.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "safe_action_family = \"repo.tool_request\"")?;
|
||||
require_text(&request_text, "[request]")?;
|
||||
require_text(&request_text, "routing_owner = \"Self\"")?;
|
||||
require_text(&request_text, "pressure_source = \"Persona\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"target_directory = \"gamecult-local/daemon-tool-directory\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"target_capability = \"daemon-tool-capability:selected-by-review\"",
|
||||
)?;
|
||||
require_text(&request_text, "operation = \"submitTypedToolIntent\"")?;
|
||||
require_text(&request_text, "[cultmesh]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"intent_contract = \"epiphany.cultmesh.daemon_tool_invocation_intent.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"receipt_contract = \"epiphany.cultmesh.daemon_tool_invocation_receipt.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "host_daemon_owns_execution = true")?;
|
||||
require_text(&request_text, "requester_owns_execution = false")?;
|
||||
require_text(&request_text, "requires_host_liveness_ready = true")?;
|
||||
require_text(&request_text, "requires_cultmesh_receipts = true")?;
|
||||
require_text(&request_text, "[odin]")?;
|
||||
require_text(&request_text, "discoverable = true")?;
|
||||
require_text(&request_text, "preserves_provider_ownership = true")?;
|
||||
require_text(&request_text, "private_verse_passthrough = false")?;
|
||||
require_text(&request_text, "[authority]")?;
|
||||
require_text(&request_text, "direct_tool_execution = false")?;
|
||||
require_text(&request_text, "arbitrary_shell_authority = false")?;
|
||||
require_text(&request_text, "hands_action_authority = false")?;
|
||||
require_text(&request_text, "state_commit_authority = false")?;
|
||||
require_text(&request_text, "publication_authority = false")?;
|
||||
require_text(&request_text, "service_lifecycle_authority = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authority = false")?;
|
||||
require_text(&request_text, "private_verse_rummaging = false")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_work_tool_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"hasCultMeshContracts": true,
|
||||
"hostDaemonOwnsExecution": true,
|
||||
"odinPreservesProviderOwnership": true,
|
||||
"directToolExecution": false,
|
||||
"arbitraryShellAuthority": false,
|
||||
"handsActionAuthority": false,
|
||||
"stateCommitAuthority": false,
|
||||
"publicationAuthority": false,
|
||||
"serviceLifecycleAuthority": false,
|
||||
"crossBodyMutationAuthority": false,
|
||||
"privateVerseRummaging": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("expected tool request text to contain {needle:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,431 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-verification-request-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Verification Request Family Smoke\n\nThis repository proves branch-local Hands verification-request requests.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(
|
||||
["commit", "-m", "Seed repo verification request smoke body"],
|
||||
&repo,
|
||||
)?;
|
||||
git(
|
||||
["switch", "-c", "epiphany/repo-verification-request-family"],
|
||||
&repo,
|
||||
)?;
|
||||
|
||||
let item = "repo-verification-request-family";
|
||||
let target_path = ".epiphany/verification-requests/repo-verification-request-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-verification-request-family-smoke",
|
||||
"--topic",
|
||||
"repo-verification-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-verification-request-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask Soul to review required Hands evidence after a bounded branch-local work order exists.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-verification-request-family/soul-review",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-verification-request-family/hands-evidence-check",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-verification-request-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-verification-request",
|
||||
"--model-ref",
|
||||
"repo-verification-request-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.verification_request",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_verification_request.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"safe_action_family = \"repo.verification_request\"",
|
||||
)?;
|
||||
require_text(&request_text, "[request]")?;
|
||||
require_text(&request_text, "status = \"awaiting-soul-review\"")?;
|
||||
require_text(&request_text, "requested_owner = \"Soul\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requested_effect = \"verify-branch-local-hands-work\"",
|
||||
)?;
|
||||
require_text(&request_text, "work_order_ref = ")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"verification_scope = \"declared changed paths, Hands receipts, and visible repo diff\"",
|
||||
)?;
|
||||
require_text(&request_text, "[antecedents]")?;
|
||||
require_text(&request_text, "substrate_gate_required = true")?;
|
||||
require_text(&request_text, "hands_intent_required = true")?;
|
||||
require_text(&request_text, "hands_review_required = true")?;
|
||||
require_text(&request_text, "hands_patch_required = true")?;
|
||||
require_text(&request_text, "hands_command_required = true")?;
|
||||
require_text(&request_text, "hands_commit_required = true")?;
|
||||
require_text(&request_text, "work_order_required = true")?;
|
||||
require_text(&request_text, "[required_receipts]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"hands_patch = \"epiphany.hands.patch_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"hands_command = \"epiphany.hands.command_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"hands_commit = \"epiphany.hands.commit_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"soul_verdict = \"epiphany.soul.verification_verdict\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"closure_review = \"epiphany.repo_work_closure_review.v0\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"mind_review = \"epiphany.mind.gateway_review\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"mind_commit = \"epiphany.mind.state_commit_receipt\"",
|
||||
)?;
|
||||
require_text(&request_text, "[checks]")?;
|
||||
require_text(&request_text, "\"declared-paths-match-commit\"")?;
|
||||
require_text(&request_text, "\"hands-receipts-present\"")?;
|
||||
require_text(&request_text, "\"visible-diff-supports-summary\"")?;
|
||||
require_text(&request_text, "\"no-private-state-exposure\"")?;
|
||||
require_text(&request_text, "\"publication-remains-gated\"")?;
|
||||
require_text(&request_text, "failure_blocks_mind_admission = true")?;
|
||||
require_text(&request_text, "soul_verdict_authorized = false")?;
|
||||
require_text(&request_text, "state_commit_authorized = false")?;
|
||||
require_text(&request_text, "hands_action_authorized = false")?;
|
||||
require_text(&request_text, "rerun_authorized = false")?;
|
||||
require_text(&request_text, "publication_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_verification_request_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingSoulReview": true,
|
||||
"soulVerdictAuthorized": false,
|
||||
"stateCommitAuthorized": false,
|
||||
"rerunAuthorized": false,
|
||||
"handsActionAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected verification request text to contain {needle:?}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,414 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-work-order-family-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
git(["init"], &repo)?;
|
||||
git(
|
||||
["config", "user.email", "epiphany-smoke@example.invalid"],
|
||||
&repo,
|
||||
)?;
|
||||
git(["config", "user.name", "Epiphany Smoke"], &repo)?;
|
||||
fs::write(
|
||||
repo.join("README.md"),
|
||||
"# Repo Work Order Family Smoke\n\nThis repository proves branch-local Hands work-order requests.\n",
|
||||
)
|
||||
.with_context(|| format!("failed to seed {}", repo.join("README.md").display()))?;
|
||||
git(["add", "README.md"], &repo)?;
|
||||
git(["commit", "-m", "Seed repo work order smoke body"], &repo)?;
|
||||
git(["switch", "-c", "epiphany/repo-work-order-family"], &repo)?;
|
||||
|
||||
let item = "repo-work-order-family";
|
||||
let target_path = ".epiphany/work-orders/repo-work-order-family.toml";
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-repo",
|
||||
&[
|
||||
"init",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--swarm-id",
|
||||
"repo-work-order-family-smoke",
|
||||
"--topic",
|
||||
"repo-work-order-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-swarm",
|
||||
&[
|
||||
"online",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--runtime-id",
|
||||
"repo-work-order-family-smoke",
|
||||
"--local-verse-store",
|
||||
path_str(&local_verse)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"accept",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--from",
|
||||
"persona",
|
||||
"--item",
|
||||
item,
|
||||
"--summary",
|
||||
"Ask Hands to review a bounded branch-local work order after Mind adoption and Self queue selection.",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-work-order-family/hands-review",
|
||||
"--candidate-action-ref",
|
||||
"candidate-action://repo-work-order-family/bounded-branch-work",
|
||||
"--public-discussion-ref",
|
||||
"epiphany-global/persona-collaboration/repo-work-order-family",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
let plan = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"derive-plan",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--item",
|
||||
item,
|
||||
"--action-family",
|
||||
"repo-work-order",
|
||||
"--model-ref",
|
||||
"repo-work-order-family-smoke-imagination-v1",
|
||||
"--model-authored",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
for _ in 0..4 {
|
||||
cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"tick",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
"--epiphany-root",
|
||||
path_str(&root)?,
|
||||
"--item",
|
||||
item,
|
||||
"--cooldown-seconds",
|
||||
"0",
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
}
|
||||
let close_path = repo
|
||||
.join(".epiphany")
|
||||
.join("work")
|
||||
.join(format!("work-close-{item}.json"));
|
||||
let close = read_json(&close_path)?;
|
||||
let request_text = fs::read_to_string(repo.join(target_path))
|
||||
.with_context(|| format!("failed to read {}", repo.join(target_path).display()))?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
&["derivation", "safeActionFamily"],
|
||||
"repo.work_order",
|
||||
)?;
|
||||
require_eq(&close, &["status"], "closed")?;
|
||||
require_eq(&close, &["soul", "verdict"], "passed")?;
|
||||
require_eq(
|
||||
&close,
|
||||
&["closureReview", "familyAssertions", "status"],
|
||||
"passed",
|
||||
)?;
|
||||
require_bool(
|
||||
&close,
|
||||
&["closureReview", "sourceGrounding", "pathScopeMatched"],
|
||||
true,
|
||||
)?;
|
||||
require_bool(&close, &["privateStateExposed"], false)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"schema_version = \"epiphany.repo_work_order.v0\"",
|
||||
)?;
|
||||
require_text(&request_text, "safe_action_family = \"repo.work_order\"")?;
|
||||
require_text(&request_text, "[work_order]")?;
|
||||
require_text(&request_text, "status = \"awaiting-hands-review\"")?;
|
||||
require_text(&request_text, "requested_owner = \"Hands\"")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"requested_effect = \"branch-local-implementation\"",
|
||||
)?;
|
||||
require_text(&request_text, "[antecedents]")?;
|
||||
require_text(&request_text, "objective_draft_ref = ")?;
|
||||
require_text(&request_text, "adoption_request_ref = ")?;
|
||||
require_text(&request_text, "scheduling_request_ref = ")?;
|
||||
require_text(&request_text, "mind_adoption_required = true")?;
|
||||
require_text(&request_text, "self_queue_selection_required = true")?;
|
||||
require_text(&request_text, "[required_receipts]")?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"substrate_gate = \"epiphany.substrate_gate.grant\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"hands_intent = \"epiphany.hands.action_intent\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"hands_review = \"epiphany.hands.action_review\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"hands_patch = \"epiphany.hands.patch_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"hands_command = \"epiphany.hands.command_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"hands_commit = \"epiphany.hands.commit_receipt\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"soul_verdict = \"epiphany.soul.verification_verdict\"",
|
||||
)?;
|
||||
require_text(
|
||||
&request_text,
|
||||
"mind_commit = \"epiphany.mind.state_commit_receipt\"",
|
||||
)?;
|
||||
require_text(&request_text, "[scope]")?;
|
||||
require_text(&request_text, "branch_required = true")?;
|
||||
require_text(&request_text, "allowed_branch_prefix = \"epiphany/\"")?;
|
||||
require_text(&request_text, "max_changed_paths = 3")?;
|
||||
require_text(&request_text, "requires_reviewable_diff = true")?;
|
||||
require_text(&request_text, "substrate_access_authorized = false")?;
|
||||
require_text(&request_text, "hands_action_authorized = false")?;
|
||||
require_text(&request_text, "shell_command_authorized = false")?;
|
||||
require_text(&request_text, "commit_authorized = false")?;
|
||||
require_text(&request_text, "cross_body_mutation_authorized = false")?;
|
||||
require_text(&request_text, "private_state_exposed = false")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_work_order_family_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"branch": git_output(["branch", "--show-current"], &repo)?,
|
||||
"item": item,
|
||||
"safeActionFamily": plan["derivation"]["safeActionFamily"],
|
||||
"targetPath": target_path,
|
||||
"closeStatus": close["status"],
|
||||
"soulVerdict": close["soul"]["verdict"],
|
||||
"familyAssertionsStatus": close["closureReview"]["familyAssertions"]["status"],
|
||||
"pathScopeMatched": close["closureReview"]["sourceGrounding"]["pathScopeMatched"],
|
||||
"awaitingHandsReview": true,
|
||||
"substrateAccessAuthorized": false,
|
||||
"shellCommandAuthorized": false,
|
||||
"commitAuthorized": false,
|
||||
"handsActionAuthorized": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn git<const N: usize>(args: [&str; N], cwd: &Path) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output<const N: usize>(args: [&str; N], cwd: &Path) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git in {}", cwd.display()))?;
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
cwd.display(),
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
serde_json::from_slice(&bytes).with_context(|| format!("failed to parse {}", path.display()))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("expected work order text to contain {needle:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
|
@ -1,516 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use sha2::Digest;
|
||||
use sha2::Sha256;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let result = run_smoke(args)?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Args {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let mut args = env::args().skip(1).peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--root" => root = take_path(&mut args, "--root")?,
|
||||
other => return Err(anyhow!("unexpected argument {other:?}")),
|
||||
}
|
||||
}
|
||||
Ok(Self { root })
|
||||
}
|
||||
}
|
||||
|
||||
fn run_smoke(args: Args) -> Result<Value> {
|
||||
let root = args
|
||||
.root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.root.display()))?;
|
||||
let smoke_root = root.join(".epiphany-smoke");
|
||||
let manifest = root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest.display()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&smoke_root)
|
||||
.with_context(|| format!("failed to create {}", smoke_root.display()))?;
|
||||
let stamp = Utc::now().format("%Y%m%d-%H%M%S").to_string();
|
||||
let smoke_dir = smoke_root.join(format!("repo-work-service-lifecycle-{stamp}"));
|
||||
fs::create_dir(&smoke_dir)
|
||||
.with_context(|| format!("failed to claim fresh smoke dir {}", smoke_dir.display()))?;
|
||||
|
||||
let repo = smoke_dir.join("repo-body");
|
||||
fs::create_dir_all(&repo).with_context(|| format!("failed to create {}", repo.display()))?;
|
||||
run_command(
|
||||
Command::new("git").arg("init").current_dir(&repo),
|
||||
"git init",
|
||||
)?;
|
||||
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
|
||||
let runbook_path = smoke_dir.join("epiphany-repo-work-queue-runner.ps1");
|
||||
let service_id = "epiphany-repo-work-queue-runner";
|
||||
let scheduler_id = "epiphany-repo-work-queue-runner";
|
||||
let runtime_id = "epiphany-local";
|
||||
let daemon_id = "epiphany-daemon-self";
|
||||
let repo_work_runtime_id = "repo-work-service-lifecycle-smoke";
|
||||
let epiphany_work_bin = root
|
||||
.join("epiphany-core")
|
||||
.join("target")
|
||||
.join("debug")
|
||||
.join(if cfg!(windows) {
|
||||
"epiphany-work.exe"
|
||||
} else {
|
||||
"epiphany-work"
|
||||
});
|
||||
let service_args = vec![
|
||||
"queue-run".to_string(),
|
||||
"--workspace".to_string(),
|
||||
path_string(&repo)?,
|
||||
"--epiphany-root".to_string(),
|
||||
path_string(&root)?,
|
||||
"--local-verse-store".to_string(),
|
||||
path_string(&local_verse)?,
|
||||
"--runtime-id".to_string(),
|
||||
repo_work_runtime_id.to_string(),
|
||||
"--max-items".to_string(),
|
||||
"1".to_string(),
|
||||
"--dry-run".to_string(),
|
||||
];
|
||||
let plan = daemon_supervisor(
|
||||
&manifest,
|
||||
&root,
|
||||
&local_verse,
|
||||
&[
|
||||
"service-plan",
|
||||
"--store",
|
||||
path_str(&local_verse)?,
|
||||
"--runtime-id",
|
||||
runtime_id,
|
||||
"--daemon-id",
|
||||
daemon_id,
|
||||
"--scheduler-id",
|
||||
scheduler_id,
|
||||
"--service-id",
|
||||
service_id,
|
||||
"--service-command",
|
||||
path_str(&epiphany_work_bin)?,
|
||||
"--reason",
|
||||
"Idunn-owned lifecycle artifact for Self-owned repo work queue-run pulse.",
|
||||
"--cwd",
|
||||
path_str(&root)?,
|
||||
],
|
||||
&service_args,
|
||||
)?;
|
||||
let runbook = daemon_supervisor(
|
||||
&manifest,
|
||||
&root,
|
||||
&local_verse,
|
||||
&[
|
||||
"service-runbook",
|
||||
"--store",
|
||||
path_str(&local_verse)?,
|
||||
"--runtime-id",
|
||||
runtime_id,
|
||||
"--daemon-id",
|
||||
daemon_id,
|
||||
"--scheduler-id",
|
||||
scheduler_id,
|
||||
"--service-id",
|
||||
service_id,
|
||||
"--service-command",
|
||||
path_str(&epiphany_work_bin)?,
|
||||
"--reason",
|
||||
"Idunn-owned lifecycle artifact for Self-owned repo work queue-run pulse.",
|
||||
"--cwd",
|
||||
path_str(&root)?,
|
||||
"--runbook-path",
|
||||
path_str(&runbook_path)?,
|
||||
],
|
||||
&service_args,
|
||||
)?;
|
||||
let runbook_receipts = receipt_directory(&manifest, &root, &local_verse, runtime_id)?;
|
||||
let runbook_rows = rows(&runbook_receipts);
|
||||
let runbook_row = runbook_rows.iter().find(|row| {
|
||||
row.get("family").and_then(Value::as_str) == Some("service-lifecycle")
|
||||
&& row.get("serviceId").and_then(Value::as_str) == Some(service_id)
|
||||
&& row.get("serviceRoute").and_then(Value::as_str)
|
||||
== Some("epiphany-repo-work-queue-runner::runbook")
|
||||
});
|
||||
let Some(runbook_row) = runbook_row else {
|
||||
return Err(anyhow!(
|
||||
"receipt directory did not expose runbook service-lifecycle row for {service_id}"
|
||||
));
|
||||
};
|
||||
require_eq(runbook_row, &["status"], "written")?;
|
||||
require_eq(runbook_row, &["artifactStatus"], "present")?;
|
||||
|
||||
let launch = daemon_supervisor(
|
||||
&manifest,
|
||||
&root,
|
||||
&local_verse,
|
||||
&[
|
||||
"service-launch",
|
||||
"--store",
|
||||
path_str(&local_verse)?,
|
||||
"--runtime-id",
|
||||
runtime_id,
|
||||
"--daemon-id",
|
||||
daemon_id,
|
||||
"--scheduler-id",
|
||||
scheduler_id,
|
||||
"--service-id",
|
||||
service_id,
|
||||
"--service-command",
|
||||
path_str(&epiphany_work_bin)?,
|
||||
"--reason",
|
||||
"Idunn-owned lifecycle launch proof for Self-owned repo work queue-run pulse.",
|
||||
"--cwd",
|
||||
path_str(&root)?,
|
||||
"--wait-child",
|
||||
],
|
||||
&service_args,
|
||||
)?;
|
||||
let launch_receipts = receipt_directory(&manifest, &root, &local_verse, runtime_id)?;
|
||||
let launch_rows = rows(&launch_receipts);
|
||||
let launch_row = launch_rows.iter().find(|row| {
|
||||
row.get("family").and_then(Value::as_str) == Some("service-lifecycle")
|
||||
&& row.get("serviceId").and_then(Value::as_str) == Some(service_id)
|
||||
&& row.get("serviceRoute").and_then(Value::as_str)
|
||||
== Some("epiphany-repo-work-queue-runner::launch")
|
||||
});
|
||||
let Some(launch_row) = launch_row else {
|
||||
return Err(anyhow!(
|
||||
"receipt directory did not expose launch service-lifecycle row for {service_id}"
|
||||
));
|
||||
};
|
||||
require_eq(launch_row, &["status"], "completed")?;
|
||||
|
||||
let audit = daemon_supervisor(
|
||||
&manifest,
|
||||
&root,
|
||||
&local_verse,
|
||||
&[
|
||||
"repo-work-service-audit",
|
||||
"--store",
|
||||
path_str(&local_verse)?,
|
||||
"--runtime-id",
|
||||
runtime_id,
|
||||
"--daemon-id",
|
||||
daemon_id,
|
||||
"--scheduler-id",
|
||||
scheduler_id,
|
||||
"--service-id",
|
||||
service_id,
|
||||
"--service-command",
|
||||
path_str(&epiphany_work_bin)?,
|
||||
"--reason",
|
||||
"Idunn-owned readiness audit for Self-owned repo work queue-run pulse.",
|
||||
"--cwd",
|
||||
path_str(&root)?,
|
||||
],
|
||||
&service_args,
|
||||
)?;
|
||||
|
||||
require_eq(&plan, &["status"], "planned")?;
|
||||
require_eq(&runbook, &["status"], "written")?;
|
||||
require_eq(&launch, &["status"], "completed")?;
|
||||
require_eq(&audit, &["status"], "complete")?;
|
||||
require_eq(&plan, &["serviceId"], service_id)?;
|
||||
require_eq(&runbook, &["serviceId"], service_id)?;
|
||||
require_eq(&launch, &["serviceId"], service_id)?;
|
||||
require_eq(&audit, &["serviceId"], service_id)?;
|
||||
require_bool(&plan, &["privateStateExposed"], false)?;
|
||||
require_bool(&runbook, &["privateStateExposed"], false)?;
|
||||
require_bool(&launch, &["privateStateExposed"], false)?;
|
||||
require_bool(&audit, &["privateStateExposed"], false)?;
|
||||
require_i64(&launch, &["exitCode"], 0)?;
|
||||
require_i64(&audit, &["launchExitCode"], 0)?;
|
||||
require_text_array_contains(&plan, &["args"], "queue-run")?;
|
||||
require_text_array_contains(&plan, &["args"], "--dry-run")?;
|
||||
require_text_array_contains(&plan, &["args"], path_str(&repo)?)?;
|
||||
require_text_array_contains(&runbook, &["args"], "queue-run")?;
|
||||
require_text_array_contains(&runbook, &["args"], "--dry-run")?;
|
||||
require_eq(&audit, &["planStatus"], "planned")?;
|
||||
require_eq(&audit, &["runbookStatus"], "written")?;
|
||||
require_eq(&audit, &["runbookArtifactStatus"], "present")?;
|
||||
require_eq(&audit, &["launchStatus"], "completed")?;
|
||||
|
||||
let runbook_text = fs::read_to_string(&runbook_path)
|
||||
.with_context(|| format!("failed to read {}", runbook_path.display()))?;
|
||||
require_text(
|
||||
&runbook_text,
|
||||
"Generated by epiphany-daemon-supervisor service-runbook",
|
||||
)?;
|
||||
require_text(&runbook_text, "Start-Process")?;
|
||||
require_text(&runbook_text, "-WindowStyle Hidden")?;
|
||||
require_text(&runbook_text, "queue-run")?;
|
||||
require_text(&runbook_text, "--dry-run")?;
|
||||
let runbook_sha256 = sha256_file(&runbook_path)?;
|
||||
|
||||
let audit_receipts = receipt_directory(&manifest, &root, &local_verse, runtime_id)?;
|
||||
let audit_rows = rows(&audit_receipts);
|
||||
let audit_row = audit_rows.iter().find(|row| {
|
||||
row.get("family").and_then(Value::as_str) == Some("service-lifecycle")
|
||||
&& row.get("serviceId").and_then(Value::as_str) == Some(service_id)
|
||||
&& row.get("serviceRoute").and_then(Value::as_str)
|
||||
== Some("epiphany-repo-work-queue-runner::repo-work-service-audit")
|
||||
});
|
||||
let Some(audit_row) = audit_row else {
|
||||
return Err(anyhow!(
|
||||
"receipt directory did not expose audit service-lifecycle row for {service_id}"
|
||||
));
|
||||
};
|
||||
require_eq(audit_row, &["status"], "complete")?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_work_service_lifecycle_smoke.v0",
|
||||
"status": "ok",
|
||||
"smokeDir": smoke_dir,
|
||||
"repo": repo,
|
||||
"localVerseStore": local_verse,
|
||||
"serviceId": service_id,
|
||||
"schedulerId": scheduler_id,
|
||||
"daemonId": daemon_id,
|
||||
"planStatus": plan["status"],
|
||||
"planReceiptId": plan["receiptId"],
|
||||
"runbookStatus": runbook["status"],
|
||||
"runbookReceiptId": runbook["receiptId"],
|
||||
"runbookPath": runbook_path,
|
||||
"runbookSha256": runbook_sha256,
|
||||
"launchStatus": launch["status"],
|
||||
"launchReceiptId": launch["receiptId"],
|
||||
"launchExitCode": launch["exitCode"],
|
||||
"auditStatus": audit["status"],
|
||||
"auditReceiptId": audit["receiptId"],
|
||||
"auditPlanStatus": audit["planStatus"],
|
||||
"auditRunbookStatus": audit["runbookStatus"],
|
||||
"auditRunbookArtifactStatus": audit["runbookArtifactStatus"],
|
||||
"auditLaunchStatus": audit["launchStatus"],
|
||||
"auditLaunchExitCode": audit["launchExitCode"],
|
||||
"serviceCommand": plan["command"],
|
||||
"serviceArgs": plan["args"],
|
||||
"lifecycleOwner": "Idunn",
|
||||
"hostedBody": "repo-work",
|
||||
"mutatesServiceManager": false,
|
||||
"launchesService": true,
|
||||
"waitChild": true,
|
||||
"requiresElevatedAuthority": false,
|
||||
"privateStateExposed": false,
|
||||
});
|
||||
write_json(&smoke_dir.join("summary.json"), &summary)?;
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
fn daemon_supervisor(
|
||||
manifest: &Path,
|
||||
cwd: &Path,
|
||||
_store: &Path,
|
||||
base_args: &[&str],
|
||||
service_args: &[String],
|
||||
) -> Result<Value> {
|
||||
let mut args = base_args
|
||||
.iter()
|
||||
.map(|arg| (*arg).to_string())
|
||||
.collect::<Vec<_>>();
|
||||
for service_arg in service_args {
|
||||
args.push("--service-arg".to_string());
|
||||
args.push(service_arg.clone());
|
||||
}
|
||||
let arg_refs = args.iter().map(String::as_str).collect::<Vec<_>>();
|
||||
cargo_json(manifest, "epiphany-daemon-supervisor", &arg_refs, cwd)
|
||||
}
|
||||
|
||||
fn cargo_json(manifest: &Path, bin: &str, args: &[&str], cwd: &Path) -> Result<Value> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest)
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--")
|
||||
.args(args)
|
||||
.current_dir(cwd)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run cargo bin {bin}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{bin} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout).with_context(|| {
|
||||
format!(
|
||||
"{bin} did not emit JSON on stdout:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn receipt_directory(
|
||||
manifest: &Path,
|
||||
root: &Path,
|
||||
local_verse: &Path,
|
||||
runtime_id: &str,
|
||||
) -> Result<Value> {
|
||||
cargo_json(
|
||||
manifest,
|
||||
"epiphany-verse-query",
|
||||
&[
|
||||
"receipt-directory",
|
||||
"--store",
|
||||
path_str(local_verse)?,
|
||||
"--runtime-id",
|
||||
runtime_id,
|
||||
],
|
||||
root,
|
||||
)
|
||||
}
|
||||
|
||||
fn rows(value: &Value) -> Vec<Value> {
|
||||
value
|
||||
.get("rows")
|
||||
.and_then(Value::as_array)
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn run_command(command: &mut Command, label: &str) -> Result<()> {
|
||||
let output = command
|
||||
.output()
|
||||
.with_context(|| format!("failed to run {label}"))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"{label} failed with status {:?}\nstdout:\n{}\nstderr:\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn sha256_file(path: &Path) -> Result<String> {
|
||||
let bytes = fs::read(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
Ok(format!("{:x}", Sha256::digest(bytes)))
|
||||
}
|
||||
|
||||
fn require_eq(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if actual == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected:?}, got {actual:?}",
|
||||
path.join(".")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_bool(value: &Value, path: &[&str], expected: bool) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_bool);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_i64(value: &Value, path: &[&str], expected: i64) -> Result<()> {
|
||||
let actual = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_i64);
|
||||
if actual == Some(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to be {expected}, got {:?}",
|
||||
path.join("."),
|
||||
actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text_array_contains(value: &Value, path: &[&str], expected: &str) -> Result<()> {
|
||||
let values = path
|
||||
.iter()
|
||||
.try_fold(value, |current, key| current.get(*key))
|
||||
.and_then(Value::as_array)
|
||||
.ok_or_else(|| anyhow!("expected {} to be an array", path.join(".")))?;
|
||||
if values.iter().any(|value| value.as_str() == Some(expected)) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"expected {} to contain {expected:?}, got {:?}",
|
||||
path.join("."),
|
||||
values
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_text(haystack: &str, needle: &str) -> Result<()> {
|
||||
if haystack.contains(needle) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("expected text to contain {needle:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
fn take_path(
|
||||
args: &mut std::iter::Peekable<impl Iterator<Item = String>>,
|
||||
flag: &str,
|
||||
) -> Result<PathBuf> {
|
||||
args.next()
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
}
|
||||
|
||||
fn path_str(path: &Path) -> Result<&str> {
|
||||
path.to_str()
|
||||
.ok_or_else(|| anyhow!("path is not valid UTF-8: {}", path.display()))
|
||||
}
|
||||
|
||||
fn path_string(path: &Path) -> Result<String> {
|
||||
Ok(path_str(path)?.to_string())
|
||||
}
|
||||
|
|
@ -1,449 +0,0 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let mut args = env::args().skip(1);
|
||||
let Some(command) = args.next() else {
|
||||
print_usage();
|
||||
std::process::exit(2);
|
||||
};
|
||||
let result = match command.as_str() {
|
||||
"init" => run_init(parse_init_args(args)?),
|
||||
other => Err(anyhow!("unknown epiphany-repo command {other:?}")),
|
||||
}?;
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct InitArgs {
|
||||
workspace: PathBuf,
|
||||
epiphany_root: PathBuf,
|
||||
artifact_dir: Option<PathBuf>,
|
||||
state_dir: Option<PathBuf>,
|
||||
swarm_id: Option<String>,
|
||||
topic: Option<String>,
|
||||
mode: String,
|
||||
model: Option<String>,
|
||||
auto_accept: bool,
|
||||
create_branch: bool,
|
||||
switch_branch: bool,
|
||||
}
|
||||
|
||||
fn parse_init_args(args: impl Iterator<Item = String>) -> Result<InitArgs> {
|
||||
let mut workspace = None;
|
||||
let mut epiphany_root = None;
|
||||
let mut artifact_dir = None;
|
||||
let mut state_dir = None;
|
||||
let mut swarm_id = None;
|
||||
let mut topic = None;
|
||||
let mut mode = "plan".to_string();
|
||||
let mut model = None;
|
||||
let mut auto_accept = false;
|
||||
let mut create_branch = false;
|
||||
let mut switch_branch = false;
|
||||
|
||||
let mut args = args.peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--workspace" => workspace = Some(take_path(&mut args, "--workspace")?),
|
||||
"--epiphany-root" => epiphany_root = Some(take_path(&mut args, "--epiphany-root")?),
|
||||
"--artifact-dir" => artifact_dir = Some(take_path(&mut args, "--artifact-dir")?),
|
||||
"--state-dir" => state_dir = Some(take_path(&mut args, "--state-dir")?),
|
||||
"--swarm-id" => swarm_id = Some(take_string(&mut args, "--swarm-id")?),
|
||||
"--topic" => topic = Some(take_string(&mut args, "--topic")?),
|
||||
"--mode" => mode = take_string(&mut args, "--mode")?,
|
||||
"--model" => model = Some(take_string(&mut args, "--model")?),
|
||||
"--auto-accept" => auto_accept = true,
|
||||
"--create-branch" => create_branch = true,
|
||||
"--switch-branch" => {
|
||||
create_branch = true;
|
||||
switch_branch = true;
|
||||
}
|
||||
other => return Err(anyhow!("unexpected init argument {other:?}")),
|
||||
}
|
||||
}
|
||||
if !matches!(mode.as_str(), "plan" | "run") {
|
||||
return Err(anyhow!("--mode must be plan or run"));
|
||||
}
|
||||
if auto_accept && mode != "run" {
|
||||
return Err(anyhow!("--auto-accept requires --mode run"));
|
||||
}
|
||||
let workspace = workspace.context("missing --workspace")?;
|
||||
let epiphany_root =
|
||||
epiphany_root.unwrap_or(env::current_dir().context("failed to resolve current directory")?);
|
||||
Ok(InitArgs {
|
||||
workspace,
|
||||
epiphany_root,
|
||||
artifact_dir,
|
||||
state_dir,
|
||||
swarm_id,
|
||||
topic,
|
||||
mode,
|
||||
model,
|
||||
auto_accept,
|
||||
create_branch,
|
||||
switch_branch,
|
||||
})
|
||||
}
|
||||
|
||||
fn run_init(args: InitArgs) -> Result<Value> {
|
||||
let workspace = args
|
||||
.workspace
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.workspace.display()))?;
|
||||
ensure_git_repo(&workspace)?;
|
||||
let epiphany_root = args
|
||||
.epiphany_root
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.epiphany_root.display()))?;
|
||||
let manifest_path = epiphany_root.join("epiphany-core").join("Cargo.toml");
|
||||
if !manifest_path.exists() {
|
||||
return Err(anyhow!(
|
||||
"could not find epiphany-core manifest at {}",
|
||||
manifest_path.display()
|
||||
));
|
||||
}
|
||||
|
||||
let workspace_name = workspace
|
||||
.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.unwrap_or("repo");
|
||||
let swarm_id = args
|
||||
.swarm_id
|
||||
.unwrap_or_else(|| sanitize(workspace_name).max_with_default("repo-swarm"));
|
||||
let topic = args
|
||||
.topic
|
||||
.unwrap_or_else(|| "first-awakening".to_string())
|
||||
.pipe(|value| sanitize(&value).max_with_default("first-awakening"));
|
||||
let branch_name = format!("epiphany/{swarm_id}/{topic}");
|
||||
let artifact_dir = args
|
||||
.artifact_dir
|
||||
.unwrap_or_else(|| workspace.join(".epiphany").join("repo-init"));
|
||||
let state_dir = args
|
||||
.state_dir
|
||||
.unwrap_or_else(|| workspace.join(".epiphany").join("state"));
|
||||
let baseline = state_dir.join("repo-personality-baseline.msgpack");
|
||||
let init_store = state_dir.join("repo-initialization.msgpack");
|
||||
let agent_store = state_dir.join("agents.msgpack");
|
||||
let heartbeat_store = state_dir.join("agent-heartbeats.msgpack");
|
||||
let runtime_store = state_dir.join("runtime-spine.msgpack");
|
||||
fs::create_dir_all(&artifact_dir)
|
||||
.with_context(|| format!("failed to create {}", artifact_dir.display()))?;
|
||||
fs::create_dir_all(&state_dir)
|
||||
.with_context(|| format!("failed to create {}", state_dir.display()))?;
|
||||
|
||||
let current_branch = git_output(&workspace, &["branch", "--show-current"])
|
||||
.unwrap_or_else(|_| "unknown".to_string());
|
||||
let branch_receipt = prepare_branch(
|
||||
&workspace,
|
||||
&branch_name,
|
||||
args.create_branch,
|
||||
args.switch_branch,
|
||||
)?;
|
||||
let birth_summary = run_birth_runner(BirthRunnerArgs {
|
||||
manifest_path: &manifest_path,
|
||||
repo: &workspace,
|
||||
baseline: &baseline,
|
||||
artifact_dir: &artifact_dir.join("birth"),
|
||||
init_store: &init_store,
|
||||
agent_store: &agent_store,
|
||||
heartbeat_store: &heartbeat_store,
|
||||
runtime_store: &runtime_store,
|
||||
mode: &args.mode,
|
||||
model: args.model.as_deref(),
|
||||
auto_accept: args.auto_accept,
|
||||
})?;
|
||||
let receipt = json!({
|
||||
"schemaVersion": "epiphany.repo_swarm_init_receipt.v0",
|
||||
"createdAt": Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
|
||||
"workspace": workspace,
|
||||
"epiphanyRoot": epiphany_root,
|
||||
"swarmId": swarm_id,
|
||||
"topic": topic,
|
||||
"branch": {
|
||||
"name": branch_name,
|
||||
"previousBranch": current_branch,
|
||||
"receipt": branch_receipt,
|
||||
},
|
||||
"stores": {
|
||||
"stateDir": state_dir,
|
||||
"baseline": baseline,
|
||||
"initStore": init_store,
|
||||
"agentStore": agent_store,
|
||||
"heartbeatStore": heartbeat_store,
|
||||
"runtimeStore": runtime_store,
|
||||
},
|
||||
"artifactDir": artifact_dir,
|
||||
"birth": birth_summary,
|
||||
"autonomyContract": {
|
||||
"standingAuthority": "branch-local work inside the owned repo Body",
|
||||
"publicationGate": "Bifrost",
|
||||
"privateState": "sealed",
|
||||
"humanRequiredBefore": ["upstream publication", "merge", "authority escalation"],
|
||||
},
|
||||
"nextSafeMove": if args.mode == "plan" {
|
||||
"Review birth packet prompts and rerun init with --mode run when Self is ready to execute startup-only distillers."
|
||||
} else if args.auto_accept {
|
||||
"Inspect auto-accepted birth receipts, then bring the repo swarm online."
|
||||
} else {
|
||||
"Review birth specialist results and run the emitted accept-init commands before epiphany-swarm online."
|
||||
}
|
||||
});
|
||||
let receipt_path = artifact_dir.join("repo-swarm-init-receipt.json");
|
||||
write_json(&receipt_path, &receipt)?;
|
||||
Ok(json!({
|
||||
"schemaVersion": "epiphany.repo_init.v0",
|
||||
"mode": "init",
|
||||
"workspace": receipt["workspace"],
|
||||
"branch": receipt["branch"],
|
||||
"stores": receipt["stores"],
|
||||
"artifactDir": receipt["artifactDir"],
|
||||
"receiptPath": receipt_path,
|
||||
"birth": {
|
||||
"schemaVersion": birth_summary["schemaVersion"],
|
||||
"mode": birth_summary["mode"],
|
||||
"executionCount": birth_summary["executions"].as_array().map_or(0, Vec::len),
|
||||
"requiresReview": birth_summary["requiresReview"],
|
||||
"nextSafeMove": birth_summary["nextSafeMove"],
|
||||
},
|
||||
"nextSafeMove": receipt["nextSafeMove"],
|
||||
}))
|
||||
}
|
||||
|
||||
struct BirthRunnerArgs<'a> {
|
||||
manifest_path: &'a Path,
|
||||
repo: &'a Path,
|
||||
baseline: &'a Path,
|
||||
artifact_dir: &'a Path,
|
||||
init_store: &'a Path,
|
||||
agent_store: &'a Path,
|
||||
heartbeat_store: &'a Path,
|
||||
runtime_store: &'a Path,
|
||||
mode: &'a str,
|
||||
model: Option<&'a str>,
|
||||
auto_accept: bool,
|
||||
}
|
||||
|
||||
fn run_birth_runner(args: BirthRunnerArgs<'_>) -> Result<Value> {
|
||||
cargo_build_support_bin(args.manifest_path, "epiphany-repo-personality")?;
|
||||
let mut command = Command::new("cargo");
|
||||
command
|
||||
.arg("run")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(args.manifest_path)
|
||||
.arg("--bin")
|
||||
.arg("epiphany-repo-birth-runner")
|
||||
.arg("--")
|
||||
.arg("--repo")
|
||||
.arg(args.repo)
|
||||
.arg("--baseline")
|
||||
.arg(args.baseline)
|
||||
.arg("--artifact-dir")
|
||||
.arg(args.artifact_dir)
|
||||
.arg("--init-store")
|
||||
.arg(args.init_store)
|
||||
.arg("--agent-store")
|
||||
.arg(args.agent_store)
|
||||
.arg("--heartbeat-store")
|
||||
.arg(args.heartbeat_store)
|
||||
.arg("--runtime-store")
|
||||
.arg(args.runtime_store)
|
||||
.arg("--mode")
|
||||
.arg(args.mode);
|
||||
if let Some(model) = args.model {
|
||||
command.arg("--model").arg(model);
|
||||
}
|
||||
if args.auto_accept {
|
||||
command.arg("--auto-accept");
|
||||
}
|
||||
let output = command
|
||||
.output()
|
||||
.context("failed to spawn epiphany-repo-birth-runner through cargo")?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"epiphany-repo-birth-runner failed:\n{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
serde_json::from_slice(&output.stdout)
|
||||
.context("epiphany-repo-birth-runner returned invalid JSON")
|
||||
}
|
||||
|
||||
fn cargo_build_support_bin(manifest_path: &Path, bin_name: &str) -> Result<()> {
|
||||
let output = Command::new("cargo")
|
||||
.arg("build")
|
||||
.arg("--quiet")
|
||||
.arg("--manifest-path")
|
||||
.arg(manifest_path)
|
||||
.arg("--bin")
|
||||
.arg(bin_name)
|
||||
.output()
|
||||
.with_context(|| format!("failed to spawn cargo build --bin {bin_name}"))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"cargo build --bin {bin_name} failed:\n{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_branch(
|
||||
workspace: &Path,
|
||||
branch_name: &str,
|
||||
create_branch: bool,
|
||||
switch_branch: bool,
|
||||
) -> Result<Value> {
|
||||
let exists = git_output(workspace, &["rev-parse", "--verify", branch_name]).is_ok();
|
||||
if !create_branch {
|
||||
return Ok(json!({
|
||||
"schemaVersion": "epiphany.repo_branch_receipt.v0",
|
||||
"status": "planned",
|
||||
"branchName": branch_name,
|
||||
"exists": exists,
|
||||
"created": false,
|
||||
"switched": false,
|
||||
"createCommand": format!("git -C {} switch -c {}", workspace.display(), branch_name),
|
||||
}));
|
||||
}
|
||||
if exists {
|
||||
if switch_branch {
|
||||
git_ok(workspace, &["switch", branch_name])?;
|
||||
}
|
||||
return Ok(json!({
|
||||
"schemaVersion": "epiphany.repo_branch_receipt.v0",
|
||||
"status": if switch_branch { "selected-existing" } else { "exists" },
|
||||
"branchName": branch_name,
|
||||
"exists": true,
|
||||
"created": false,
|
||||
"switched": switch_branch,
|
||||
}));
|
||||
}
|
||||
let mut args = vec!["branch", branch_name];
|
||||
if switch_branch {
|
||||
args = vec!["switch", "-c", branch_name];
|
||||
}
|
||||
git_ok(workspace, &args)?;
|
||||
Ok(json!({
|
||||
"schemaVersion": "epiphany.repo_branch_receipt.v0",
|
||||
"status": if switch_branch { "created-and-selected" } else { "created" },
|
||||
"branchName": branch_name,
|
||||
"exists": false,
|
||||
"created": true,
|
||||
"switched": switch_branch,
|
||||
}))
|
||||
}
|
||||
|
||||
fn ensure_git_repo(workspace: &Path) -> Result<()> {
|
||||
git_ok(workspace, &["rev-parse", "--show-toplevel"])
|
||||
.with_context(|| format!("{} is not a git repository", workspace.display()))
|
||||
}
|
||||
|
||||
fn git_ok(workspace: &Path, args: &[&str]) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.arg("-C")
|
||||
.arg(workspace)
|
||||
.args(args)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git {}", args.join(" ")))?;
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"git {} failed: {}",
|
||||
args.join(" "),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn git_output(workspace: &Path, args: &[&str]) -> Result<String> {
|
||||
let output = Command::new("git")
|
||||
.arg("-C")
|
||||
.arg(workspace)
|
||||
.args(args)
|
||||
.output()
|
||||
.with_context(|| format!("failed to run git {}", args.join(" ")))?;
|
||||
if !output.status.success() {
|
||||
return Err(anyhow!(
|
||||
"git {} failed: {}",
|
||||
args.join(" "),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
}
|
||||
|
||||
fn take_path(args: &mut impl Iterator<Item = String>, name: &str) -> Result<PathBuf> {
|
||||
Ok(PathBuf::from(take_string(args, name)?))
|
||||
}
|
||||
|
||||
fn take_string(args: &mut impl Iterator<Item = String>, name: &str) -> Result<String> {
|
||||
args.next()
|
||||
.ok_or_else(|| anyhow!("missing value for {name}"))
|
||||
}
|
||||
|
||||
fn write_json(path: &Path, value: &Value) -> Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
fs::write(path, serde_json::to_vec_pretty(value)?)
|
||||
.with_context(|| format!("failed to write {}", path.display()))
|
||||
}
|
||||
|
||||
fn sanitize(value: &str) -> String {
|
||||
value
|
||||
.chars()
|
||||
.map(|ch| {
|
||||
if ch.is_ascii_alphanumeric() {
|
||||
ch.to_ascii_lowercase()
|
||||
} else {
|
||||
'-'
|
||||
}
|
||||
})
|
||||
.collect::<String>()
|
||||
.split('-')
|
||||
.filter(|part| !part.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
.join("-")
|
||||
}
|
||||
|
||||
trait NonEmptyDefault {
|
||||
fn max_with_default(self, fallback: &str) -> String;
|
||||
}
|
||||
|
||||
impl NonEmptyDefault for String {
|
||||
fn max_with_default(self, fallback: &str) -> String {
|
||||
if self.is_empty() {
|
||||
fallback.to_string()
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait Pipe: Sized {
|
||||
fn pipe<T>(self, f: impl FnOnce(Self) -> T) -> T {
|
||||
f(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Pipe for T {}
|
||||
|
||||
fn print_usage() {
|
||||
eprintln!(
|
||||
"usage: epiphany-repo init --workspace <repo> [--epiphany-root <path>] [--artifact-dir <path>] [--state-dir <path>] [--swarm-id <id>] [--topic <topic>] [--mode plan|run] [--model <model>] [--auto-accept] [--create-branch|--switch-branch]"
|
||||
);
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
use anyhow::{Result, anyhow};
|
||||
use epiphany_core::migrate_runtime_store_to_redb;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let mut args = std::env::args().skip(1);
|
||||
let source = args.next().ok_or_else(|| anyhow!("usage: epiphany-runtime-store-migrate <source.cc> <destination.redb> <migrated-at-rfc3339>"))?;
|
||||
let destination = args
|
||||
.next()
|
||||
.ok_or_else(|| anyhow!("missing destination.redb"))?;
|
||||
let migrated_at = args
|
||||
.next()
|
||||
.ok_or_else(|| anyhow!("missing migrated-at-rfc3339"))?;
|
||||
if args.next().is_some() {
|
||||
return Err(anyhow!("unexpected extra migration arguments"));
|
||||
}
|
||||
let receipt = migrate_runtime_store_to_redb(source, destination, &migrated_at)?;
|
||||
println!(
|
||||
"{}",
|
||||
rmp_serde::to_vec_named(&receipt)?
|
||||
.iter()
|
||||
.map(|byte| format!("{byte:02x}"))
|
||||
.collect::<String>()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
Reference in a new issue