proto becomes bxcore, the one shared crate (M5b task 00)

Done the way the owner asked and the spike mapped: the crate and the
manifests renamed, then what the build reported fixed. Layers: 138
"proto unresolved" errors across 169 files; cargo fmt reordering
imports; six fixture paths built as strings in brokerd's and bxctl's
tests, which the compiler cannot see, and comments naming
crates/proto/; the crate-dependency check and its self-test. One more
the spike did not reach: a `\nproto =` key inside a printf format in
the self-test, which a word-boundary replacement skips because `n` and
`p` are both word characters.

make gate: gate: ok, 944 tests; no new entry in /tmp.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-26 01:48:38 -07:00
co-authored by Claude Opus 5.5
parent 727e027fcf
commit 2b3ae080b4
311 changed files with 426 additions and 410 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ publish.workspace = true
workspace = true
[dependencies]
proto.workspace = true
bxcore.workspace = true
serde.workspace = true
serde_json.workspace = true
toml.workspace = true
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::approvals::Entry;
use crate::broker::{Broker, forbid, read_request, send};
use crate::grants;
use crate::ledger::{Answer, Answered};
use proto::{
use bxcore::{
ApprovalList, Approve, ApproveResult, DecisionRecord, DenyReason, Empty, ErrorCode,
GrantsReport, Message, Refuse, Timestamp, WireError,
};
+1 -1
View File
@@ -2,7 +2,7 @@
//! gone. In memory only.
use crate::policy::{Ask, Decision};
use proto::{DecisionRecord, DenyReason, PendingApproval, Timestamp};
use bxcore::{DecisionRecord, DenyReason, PendingApproval, Timestamp};
use std::collections::BTreeMap;
use std::sync::mpsc::{Receiver, Sender, channel};
use std::sync::{Mutex, MutexGuard};
+4 -4
View File
@@ -4,8 +4,8 @@
//! path, a host or a URL is well formed. The module is pure: no I/O, no clock. Everything it reads
//! was written by the model, so it is treated as hostile.
use proto::tools::{HttpFetchArgs, ReadFileArgs, ShellArgs, WriteFileArgs};
use proto::{MemoryArgs, RecallArgs};
use bxcore::tools::{HttpFetchArgs, ReadFileArgs, ShellArgs, WriteFileArgs};
use bxcore::{MemoryArgs, RecallArgs};
use std::fmt;
/// Maximum length, in bytes, of a path.
@@ -295,8 +295,8 @@ pub fn inside(grant_path: &str, path: &str) -> bool {
}
}
/// Moved to `proto::hosts` in M3b, so `toolkit` checks hosts with the same rules.
pub use proto::hosts::{host_matches, valid_host, valid_host_pattern};
/// Moved to `bxcore::hosts` in M3b, so `toolkit` checks hosts with the same rules.
pub use bxcore::hosts::{host_matches, valid_host, valid_host_pattern};
/// A character that may appear in a host name.
fn host_char(c: char) -> bool {
+1 -1
View File
@@ -10,7 +10,7 @@ use std::io::Write;
use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt};
use std::path::{Path, PathBuf};
use proto::{
use bxcore::{
AuditEvent, AuditRecord, ChainFailure, ChainReport, ChainVerifier, Hash32, Timestamp,
is_audit_log_name, sha256,
};
+2 -2
View File
@@ -9,7 +9,7 @@ use std::sync::Mutex;
use std::sync::mpsc::{Receiver, RecvTimeoutError};
use std::time::Duration;
use proto::{
use bxcore::{
DenyReason, Envelope, ErrorCode, FrameError, Message, PROTOCOL_VERSION, PendingApproval,
Timestamp, ToolResponse, WireError, read_frame, write_frame,
};
@@ -37,7 +37,7 @@ pub struct Broker {
table: Table,
runtime: Box<dyn Runtime>,
log: Log,
printed: Mutex<Option<Vec<proto::GrantProblem>>>,
printed: Mutex<Option<Vec<bxcore::GrantProblem>>>,
}
impl Broker {
+1 -1
View File
@@ -2,7 +2,7 @@
//! is what an agent is, so no grant file can turn it off or put questions in front of it; the
//! prompt is protected by `memoryd`, which lets only clean sessions edit identity.
use proto::{Grant, GrantProblem, sha256};
use bxcore::{Grant, GrantProblem, sha256};
use crate::grants::LoadedGrant;
+1 -1
View File
@@ -8,7 +8,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{self, Receiver, RecvTimeoutError};
use std::time::{Duration, Instant};
use proto::{
use bxcore::{
ApprovalOutcome, ApprovalReply, ApprovalRequest, DecisionRecord, DenyReason, Envelope,
FrameError, GatewayOutcome, Message, PendingApproval, Timestamp, read_frame,
};
+3 -3
View File
@@ -8,7 +8,7 @@
use std::path::Path;
use crate::args::{ToolName, valid_host_pattern, valid_path};
use proto::{DataClass, Grant, GrantProblem, Mode, sha256};
use bxcore::{DataClass, Grant, GrantProblem, Mode, sha256};
/// Where the owner reads the rules behind a rejected set.
pub const RUNBOOK: &str = "see docs/runbook.md#grants-invalid";
@@ -17,8 +17,8 @@ pub const RUNBOOK: &str = "see docs/runbook.md#grants-invalid";
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LoadedGrant {
pub id: String, // the file stem
pub grant: proto::Grant,
pub sha256: proto::Hash32, // of the file's bytes as read
pub grant: bxcore::Grant,
pub sha256: bxcore::Hash32, // of the file's bytes as read
}
/// A set that passed every rule, in id order. Its field is private: `from_grants` and `load` are
+6 -6
View File
@@ -2,7 +2,7 @@
use std::sync::MutexGuard;
use proto::{ApprovalAnswer, AuditEvent, DataClass, DenyReason, Timestamp, ToolResponse};
use bxcore::{ApprovalAnswer, AuditEvent, DataClass, DenyReason, Timestamp, ToolResponse};
use super::{Answer, Answered, Call, Grants, Inner, Ledger};
use crate::approvals::Verdict;
@@ -107,16 +107,16 @@ impl Ledger {
guard: &mut MutexGuard<'_, Inner>,
call: &Call,
now: Timestamp,
status: proto::ResultStatus,
status: bxcore::ResultStatus,
taint_after: DataClass,
response: &ToolResponse,
) -> ToolResponse {
let (sha256, bytes) = match response {
ToolResponse::Result { content, .. } => match proto::sha256(content.as_bytes()) {
ToolResponse::Result { content, .. } => match bxcore::sha256(content.as_bytes()) {
Ok(sha) => (sha, u64::try_from(content.len()).unwrap_or(u64::MAX)),
Err(_) => return Self::not_recorded(),
},
ToolResponse::Failed { message } => match proto::sha256(message.as_bytes()) {
ToolResponse::Failed { message } => match bxcore::sha256(message.as_bytes()) {
Ok(sha) => (sha, u64::try_from(message.len()).unwrap_or(u64::MAX)),
Err(_) => return Self::not_recorded(),
},
@@ -182,7 +182,7 @@ impl Ledger {
&mut guard,
call,
now,
proto::ResultStatus::Result,
bxcore::ResultStatus::Result,
raised.taint,
&response,
)
@@ -197,7 +197,7 @@ impl Ledger {
&mut guard,
call,
now,
proto::ResultStatus::Failed,
bxcore::ResultStatus::Failed,
taint_after,
&response,
)
+1 -1
View File
@@ -6,7 +6,7 @@ mod answer;
use std::sync::{Mutex, MutexGuard};
use proto::{
use bxcore::{
AuditEvent, CallId, DataClass, DecisionRecord, DenyReason, GrantProblem, Mode, SessionId,
Timestamp, ToolRequest, ToolResponse,
};
+1 -1
View File
@@ -6,7 +6,7 @@ use std::os::unix::net::UnixStream;
use std::path::PathBuf;
use std::time::Duration;
use proto::{
use bxcore::{
Envelope, MemoryCall, Message, PROTOCOL_VERSION, ToolRequest, ToolResponse, read_frame,
write_frame,
};
+1 -1
View File
@@ -6,7 +6,7 @@
use crate::config::Runner;
use crate::runner::RunSpec;
use proto::{CallId, SessionId};
use bxcore::{CallId, SessionId};
use std::ffi::OsString;
use std::path::Path;
+1 -1
View File
@@ -3,7 +3,7 @@
use super::{Label, Matched, SessionState};
use crate::args::{ToolArgs, host_matches, inside};
use crate::grants::GrantSet;
use proto::{DataClass, Grant, Hash32, Mode, Timestamp};
use bxcore::{DataClass, Grant, Hash32, Mode, Timestamp};
/// The grants left after matching, and the two flags that pick the denial reason when none are
/// left.
+14 -14
View File
@@ -6,9 +6,9 @@
//! constructor is exposed.
//!
//! ```compile_fail
//! let request = proto::ToolRequest {
//! session: proto::SessionId::new("s1").unwrap(),
//! call: proto::CallId(1),
//! let request = bxcore::ToolRequest {
//! session: bxcore::SessionId::new("s1").unwrap(),
//! call: bxcore::CallId(1),
//! tool: "shell".to_string(),
//! arguments: r#"{"command":"ls"}"#.to_string(),
//! };
@@ -33,9 +33,9 @@
//! The same three hold for `Ask`.
//!
//! ```compile_fail
//! let request = proto::ToolRequest {
//! session: proto::SessionId::new("s1").unwrap(),
//! call: proto::CallId(1),
//! let request = bxcore::ToolRequest {
//! session: bxcore::SessionId::new("s1").unwrap(),
//! call: bxcore::CallId(1),
//! tool: "shell".to_string(),
//! arguments: r#"{"command":"ls"}"#.to_string(),
//! };
@@ -60,15 +60,15 @@
//! ```
//! fn needs_clone<T: Clone>() {}
//! fn needs_decoding<T: serde::de::DeserializeOwned>() {}
//! needs_clone::<proto::ToolRequest>();
//! needs_decoding::<proto::ToolRequest>();
//! let request = proto::ToolRequest {
//! session: proto::SessionId::new("s1").unwrap(),
//! call: proto::CallId(1),
//! needs_clone::<bxcore::ToolRequest>();
//! needs_decoding::<bxcore::ToolRequest>();
//! let request = bxcore::ToolRequest {
//! session: bxcore::SessionId::new("s1").unwrap(),
//! call: bxcore::CallId(1),
//! tool: "shell".to_string(),
//! arguments: r#"{"command":"ls"}"#.to_string(),
//! };
//! let now = proto::Timestamp::from_unix_millis(0).unwrap();
//! let now = bxcore::Timestamp::from_unix_millis(0).unwrap();
//! match brokerd::policy::decide(
//! request,
//! &brokerd::grants::GrantSet::default(),
@@ -76,7 +76,7 @@
//! now,
//! ) {
//! brokerd::policy::Outcome::Denied(denial) => {
//! assert_eq!(denial.reason, proto::DenyReason::NoGrant);
//! assert_eq!(denial.reason, bxcore::DenyReason::NoGrant);
//! }
//! other => panic!("expected a denial, got {other:?}"),
//! }
@@ -86,8 +86,8 @@ mod matching;
use crate::args::{self, ToolArgs, ToolName};
use crate::grants::GrantSet;
use bxcore::{DataClass, DenyReason, Hash32, Mode, Timestamp, ToolRequest};
use matching::{MatchResult, build_matched, match_grants, winner};
use proto::{DataClass, DenyReason, Hash32, Mode, Timestamp, ToolRequest};
/// The session's taint, and whether its results are untrusted. Only `taint` shapes a decision.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+4 -4
View File
@@ -5,8 +5,8 @@
//!
//! ```compile_fail
//! let _ = brokerd::runner::RunSpec {
//! session: proto::SessionId::new("s1").unwrap(),
//! call: proto::CallId(1),
//! session: bxcore::SessionId::new("s1").unwrap(),
//! call: bxcore::CallId(1),
//! tool: brokerd::args::ToolName::Shell,
//! arguments: todo!(),
//! mounts: Vec::new(),
@@ -22,7 +22,7 @@
use crate::args::{ToolArgs, ToolName};
use crate::policy::{Decision, Label, SessionState};
use proto::{CallId, SessionId, ToolResponse};
use bxcore::{CallId, SessionId, ToolResponse};
/// A directory mounted for one call: a path and whether the runtime may write to it.
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -111,7 +111,7 @@ pub const REFUSING: &str = "no tool runner is configured: brokerd.toml has no [r
/// Turn an allowed call into a `RunSpec`, run it, and answer. A `RunError`'s text reaches the
/// model unchanged, so a runtime may only put a fixed sentence in it.
pub fn run(decision: Decision, runtime: &dyn Runtime) -> proto::ToolResponse {
pub fn run(decision: Decision, runtime: &dyn Runtime) -> bxcore::ToolResponse {
let label = decision.label();
let args = decision.args();
let (mounts, egress) = match args {
+1 -1
View File
@@ -16,7 +16,7 @@ use crate::config::Config;
use crate::ledger::Ledger;
use crate::runner::Runtime;
use crate::state::StateStore;
use proto::{ChainFailure, Timestamp};
use bxcore::{ChainFailure, Timestamp};
/// A failure while `brokerd serve` is starting up.
#[derive(Debug)]
+1 -1
View File
@@ -5,7 +5,7 @@
//! The file's format is private (`StateFile`), so `SessionState` stays free of serde.
use crate::policy::{Label, SessionState};
use proto::{DataClass, SessionId};
use bxcore::{DataClass, SessionId};
use serde::{Deserialize, Serialize};
use std::fs;
use std::io::{self, Write};
+2 -2
View File
@@ -19,11 +19,11 @@ use std::time::{Duration, Instant};
use brokerd::admin;
use brokerd::broker::{self, Broker};
use brokerd::policy::Label;
use client::{Serve, next, open};
use proto::{
use bxcore::{
ApprovalAnswer, Approve, AuditEvent, DataClass, DecisionRecord, DenyReason, Empty, ErrorCode,
Message, Refuse, SessionId, Timestamp, ToolResponse,
};
use client::{Serve, next, open};
use rig::{Rig, grant_text, request};
use runtime::Recording;
+1 -1
View File
@@ -9,7 +9,7 @@ use std::sync::{Arc, Barrier};
use brokerd::approvals::{Table, Verdict};
use brokerd::policy::{Ask, Outcome, SessionState, decide};
use build::{grant, now, read, set, ts};
use proto::{CallId, DataClass, DenyReason, Mode, PendingApproval, SessionId, Timestamp};
use bxcore::{CallId, DataClass, DenyReason, Mode, PendingApproval, SessionId, Timestamp};
fn ask() -> Ask {
let grants = set(vec![grant("n", "read_file", Mode::Ask).paths(&["/n"])]);
+1 -1
View File
@@ -8,7 +8,7 @@ use std::os::unix::fs::PermissionsExt;
use audit_dir::{D1, D2, TempDir, denied, lines, ts};
use brokerd::audit::{AuditError, RECOVERED_NOTICE, Writer, verify_dir};
use proto::{AuditRecord, Hash32, sha256};
use bxcore::{AuditRecord, Hash32, sha256};
fn mode(path: &std::path::Path) -> u32 {
std::fs::metadata(path).unwrap().permissions().mode() & 0o777
+1 -1
View File
@@ -6,7 +6,7 @@ mod audit_dir;
use audit_dir::{D1, D2, TempDir, denied, lines, ts};
use brokerd::audit::{Writer, verify_dir};
use proto::{AuditRecord, Hash32};
use bxcore::{AuditRecord, Hash32};
/// A kill between creating the day's file and writing its first record leaves it empty. It must
/// open like an empty log, not panic.
+2 -2
View File
@@ -1,13 +1,13 @@
//! What `Writer::open` does with the log it finds: refuse a broken chain, recover a torn tail,
//! accept a break when told to. Do not edit. The fixture logs are in
//! `crates/proto/tests/fixtures/audit/`; each test works on a copy.
//! `crates/bxcore/tests/fixtures/audit/`; each test works on a copy.
#[path = "support/audit_dir.rs"]
mod audit_dir;
use audit_dir::{D1, D2, TempDir, denied, lines, snapshot};
use brokerd::audit::{AuditError, Writer, verify_dir};
use proto::{AuditEvent, AuditRecord, Location, Timestamp};
use bxcore::{AuditEvent, AuditRecord, Location, Timestamp};
type Case = (
&'static str,
+3 -3
View File
@@ -20,18 +20,18 @@ use std::sync::Arc;
use brokerd::broker;
use brokerd::ledger::NOT_RECORDED;
use brokerd::runner::{REFUSING, RunError};
use client::{Serve, call, next, open};
use proto::{
use bxcore::{
ApprovalList, Approve, ApproveResult, AuditEvent, DataClass, DecisionRecord, DenyReason, Empty,
Envelope, ErrorCode, GrantsReport, Message, Refuse, ResultStatus, SessionId, ToolResponse,
Turn, TurnDone, TurnEvent, Usage, WireError,
};
use client::{Serve, call, next, open};
use rig::{Rig, grant_text, request};
use runtime::Recording;
const NOTES: &str = r#"{"path":"/n/a"}"#;
fn read_notes(call_id: u64) -> proto::ToolRequest {
fn read_notes(call_id: u64) -> bxcore::ToolRequest {
request("s1", call_id, "read_file", NOTES)
}
+3 -3
View File
@@ -18,11 +18,11 @@ use std::time::{Duration, Instant};
use brokerd::broker::{self, Broker, GONE};
use brokerd::ledger::Answer;
use client::{Serve, next, open};
use proto::{
use bxcore::{
AuditEvent, DataClass, DecisionRecord, DenyReason, Message, ResultStatus, Timestamp,
ToolResponse,
};
use client::{Serve, next, open};
use rig::{Rig, grant_text, request};
use runtime::Recording;
@@ -220,7 +220,7 @@ fn a_requester_gone_at_the_last_look_runs_nothing_and_closes_the_call() {
..
} => {
assert_eq!((*status, *decision), (ResultStatus::Failed, 0));
assert_eq!(*sha256, proto::sha256(GONE.as_bytes()).unwrap());
assert_eq!(*sha256, bxcore::sha256(GONE.as_bytes()).unwrap());
assert_eq!(*bytes, GONE.len() as u64);
}
other => panic!("{other:?}"),
+2 -2
View File
@@ -20,11 +20,11 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;
use brokerd::ledger::Answer;
use client::{Serve, call};
use proto::{
use bxcore::{
AuditEvent, AuditRecord, CallId, DataClass, DecisionRecord, Message, SessionId, Timestamp,
ToolResponse,
};
use client::{Serve, call};
use rig::{Rig, grant_text, request};
use runtime::Recording;
+1 -1
View File
@@ -15,8 +15,8 @@ use brokerd::container::{
use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::run;
use build::{grant, now, read, request, set};
use bxcore::{DataClass, Mode, ToolRequest, ToolResponse};
use fake_podman::{Fake, Lines, serial};
use proto::{DataClass, Mode, ToolRequest, ToolResponse};
fn call(podman: &Podman, req: ToolRequest, grants: Vec<build::Build>) -> ToolResponse {
let decision = match decide(req, &set(grants), SessionState::default(), now()) {
+1 -1
View File
@@ -14,8 +14,8 @@ use brokerd::container::{CANNOT_START, Podman, RUNBOOK, TIMED_OUT};
use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::run;
use build::{fetch, grant, now, set};
use bxcore::{Mode, ToolResponse};
use fake_podman::{Fake, Lines, path, serial};
use proto::{Mode, ToolResponse};
/// For `run -d` (the proxy): make the socket file in the mounted directory, as the proxy does.
const PROXY_OK: &str = r#"for a in "$@"; do case "$a" in --volume=*:/run/egress:rw) v=${a#--volume=}; v=${v%:/run/egress:rw};; esac; done"#;
+1 -1
View File
@@ -15,8 +15,8 @@ use brokerd::pipes::GRACE;
use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::run;
use build::{grant, now, read, set};
use bxcore::{Mode, ToolResponse};
use fake_podman::{Fake, Lines, serial};
use proto::{Mode, ToolResponse};
fn call(fake: &Fake, extra: &str, log: &Lines) -> (ToolResponse, Duration) {
let podman = Podman::new(fake.runner(extra), fake.dir.join("egress"), log.sink());
+1 -1
View File
@@ -11,8 +11,8 @@ use brokerd::container::{CANNOT_START, COULD_NOT_RUN, Podman, UNEXPECTED};
use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::run;
use build::{fetch, grant, now, read, set};
use bxcore::{Mode, ToolRequest, ToolResponse};
use fake_podman::{Fake, Lines, serial};
use proto::{Mode, ToolRequest, ToolResponse};
const FORGED: &str = "real line\nbrokerd: forged\nsee docs/runbook.md#grants-invalid";
+3 -3
View File
@@ -23,12 +23,12 @@ use brokerd::broker::{self, Broker};
use brokerd::config::Gateway;
use brokerd::courier::{self, Timing};
use brokerd::ledger::Answer;
use client::{Serve, next, open};
use fake_gateway::{FakeGateway, KYLE, POST};
use proto::{
use bxcore::{
ApprovalAnswer, ApprovalReply, AuditEvent, DenyReason, GatewayOutcome, Message, Timestamp,
ToolResponse,
};
use client::{Serve, next, open};
use fake_gateway::{FakeGateway, KYLE, POST};
use rig::{Rig, grant_text, request};
use runtime::Recording;
+3 -3
View File
@@ -7,7 +7,7 @@
mod tmp;
use brokerd::grants::{GrantSet, LoadedGrant, RUNBOOK, load, render, valid_id};
use proto::{Constraints, DataClass, Grant, GrantProblem, Hash32, Mode};
use bxcore::{Constraints, DataClass, Grant, GrantProblem, Hash32, Mode};
use std::path::{Path, PathBuf};
use tmp::TempDir;
@@ -66,8 +66,8 @@ fn the_valid_fixture_loads_in_id_order_with_file_hashes() {
assert!(!notes.grant.untrusted);
assert_eq!(notes.grant.constraints.paths, ["/home/kyle/notes"]);
let bytes = std::fs::read(fixture("valid").join("notes-read.toml")).unwrap();
assert_eq!(notes.sha256, proto::sha256(&bytes).unwrap());
// Defaults from `proto::Grant`.
assert_eq!(notes.sha256, bxcore::sha256(&bytes).unwrap());
// Defaults from `bxcore::Grant`.
let scratch = &set.grants()[3];
assert_eq!(scratch.grant.result_class, DataClass::Private);
assert!(scratch.grant.untrusted);
+4 -4
View File
@@ -16,7 +16,7 @@ use std::panic::AssertUnwindSafe;
use brokerd::ledger::{Call, Decided, Grants, NOT_RECORDED, POISONED, STOPPED};
use brokerd::policy::{Label, SessionState};
use build::{grant, now, read, set};
use proto::{
use bxcore::{
AuditEvent, CallId, DataClass, DecisionRecord, DenyReason, GrantProblem, Mode, ResultStatus,
SessionId, ToolResponse,
};
@@ -80,7 +80,7 @@ fn an_allowed_call_is_recorded_in_full() {
arguments,
outcome: DecisionRecord::Allowed {},
grant: Some("n".to_string()),
grant_sha256: Some(proto::sha256(b"n").unwrap()),
grant_sha256: Some(bxcore::sha256(b"n").unwrap()),
taint: DataClass::Private,
untrusted: false,
}
@@ -270,7 +270,7 @@ fn a_result_raises_the_state_then_is_recorded() {
untrusted: true,
truncated: false,
bytes: 3,
sha256: proto::sha256(b"key").unwrap(),
sha256: bxcore::sha256(b"key").unwrap(),
taint_after: DataClass::Secret,
}]
);
@@ -327,7 +327,7 @@ fn a_failure_changes_no_state_and_is_recorded_by_its_message() {
"the label the result would have had"
);
assert_eq!(*bytes, 18);
assert_eq!(*sha256, proto::sha256(b"the tool timed out").unwrap());
assert_eq!(*sha256, bxcore::sha256(b"the tool timed out").unwrap());
assert_eq!(*taint_after, DataClass::Private, "the taint before");
}
other => panic!("{other:?}"),
+1 -1
View File
@@ -14,7 +14,7 @@ use brokerd::approvals::Verdict;
use brokerd::ledger::{Answer, Answered, Decided, Grants, Ledger};
use brokerd::policy::{Ask, Label};
use build::{grant, now, read, set};
use proto::{
use bxcore::{
ApprovalAnswer, AuditEvent, CallId, DataClass, DecisionRecord, DenyReason, Mode, SessionId,
};
use rig::Rig;
+1 -1
View File
@@ -15,7 +15,7 @@ mod tmp;
use brokerd::ledger::Call;
use brokerd::policy::{Label, SessionState};
use build::now;
use proto::{AuditEvent, CallId, DataClass, SessionId, ToolResponse};
use bxcore::{AuditEvent, CallId, DataClass, SessionId, ToolResponse};
use rig::Rig;
fn label(class: DataClass, untrusted: bool) -> Label {
+1 -1
View File
@@ -14,7 +14,7 @@ use brokerd::approvals::Table;
use brokerd::ledger::{Answer, Decided, Grants, Ledger};
use brokerd::policy::Ask;
use build::{grant, now, read, set};
use proto::{ApprovalAnswer, AuditEvent, CallId, DataClass, Mode, PendingApproval, SessionId};
use bxcore::{ApprovalAnswer, AuditEvent, CallId, DataClass, Mode, PendingApproval, SessionId};
use rig::Rig;
const KYLE: &str = "k0000000000000000000000000";
+2 -2
View File
@@ -21,11 +21,11 @@ use brokerd::memory_port::{MemoryPort, Routed, UNREACHABLE};
use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::run;
use build::{grant, now, read, request, set};
use fake_podman::{Fake, Lines, serial};
use proto::{
use bxcore::{
DataClass, Envelope, MemoryCall, Message, Mode, ToolRequest, ToolResponse, read_frame,
write_frame,
};
use fake_podman::{Fake, Lines, serial};
use runtime::{Recording, Shared};
use tmp::TempDir;
+1 -1
View File
@@ -11,7 +11,7 @@ use brokerd::builtin::{BUILT_IN, MEMORY, RECALL};
use brokerd::grants::{GrantSet, load};
use brokerd::policy::{Label, Outcome, decide};
use build::{allowed, grant, now, private, request, secret, set};
use proto::{DataClass, DenyReason, Mode, sha256};
use bxcore::{DataClass, DenyReason, Mode, sha256};
use tmp::TempDir;
#[test]
+1 -1
View File
@@ -14,7 +14,7 @@ use brokerd::podman::{container_name, egress_args, tool_args};
use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::{RunError, RunOutput, RunSpec, Runtime, run};
use build::{fetch, grant, now, read, request, set, shell, write};
use proto::{CallId, Mode, SessionId, ToolRequest};
use bxcore::{CallId, Mode, SessionId, ToolRequest};
const IMAGE: &str = "localhost/boxmaker-tools@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
+1 -1
View File
@@ -7,7 +7,7 @@ mod build;
use brokerd::policy::decide;
use build::{allowed, fetch, grant, now, private, read, reason, request, set, shell, write};
use proto::{DenyReason, Mode};
use bxcore::{DenyReason, Mode};
#[test]
fn no_grants_means_no_grant() {
+2 -2
View File
@@ -8,7 +8,7 @@ use brokerd::policy::{Label, decide};
use build::{
allowed, asked, denied, fetch, grant, now, private, read, reason, request, secret, set, shell,
};
use proto::{DataClass, DenyReason, Mode};
use bxcore::{DataClass, DenyReason, Mode};
#[test]
fn the_most_restrictive_mode_wins_among_three_matching_grants() {
@@ -348,7 +348,7 @@ fn a_decision_and_an_ask_carry_what_the_broker_and_the_runner_need() {
r#"{"path":"/home/kyle/scratch/a.txt","content":"hello"}"#
);
assert_eq!(ask.grant(), "asks");
assert_eq!(ask.grant_sha256(), proto::sha256(b"asks").unwrap());
assert_eq!(ask.grant_sha256(), bxcore::sha256(b"asks").unwrap());
assert_eq!(ask.matched_path(), Some("/home/kyle/scratch"));
assert_eq!(ask.paths(), ["/home/kyle/scratch"]);
assert!(ask.hosts().is_empty());
+1 -1
View File
@@ -13,8 +13,8 @@ mod oracle;
use brokerd::grants::{GrantSet, LoadedGrant};
use brokerd::policy::{Outcome, SessionState, decide, redecide};
use bxcore::{DataClass, DenyReason, Mode, Timestamp};
use oracle::{CLASSES, Expected, NOW_MS, Rng, oracle, some_grant, some_grants, some_request};
use proto::{DataClass, DenyReason, Mode, Timestamp};
const SEEDS: [u64; 5] = [1, 2, 3, 0xB0C5, 20_260_918];
+6 -3
View File
@@ -7,7 +7,7 @@ mod build;
use brokerd::grants::GrantSet;
use brokerd::policy::{Ask, Label, Outcome, decide, redecide};
use build::{grant, now, private, read, secret, set};
use proto::{DataClass, DenyReason, Mode};
use bxcore::{DataClass, DenyReason, Mode};
const PATH: &str = "/home/kyle/notes/a.md";
@@ -49,7 +49,10 @@ fn auto_now_lets_the_call_run_under_the_grant_that_matches_now() {
]);
let decision = redecide(pending(), &grants, private(), now()).unwrap();
assert_eq!(decision.grant(), "now-auto");
assert_eq!(decision.grant_sha256(), proto::sha256(b"now-auto").unwrap());
assert_eq!(
decision.grant_sha256(),
bxcore::sha256(b"now-auto").unwrap()
);
assert_eq!(decision.matched_path(), Some("/home/kyle"));
assert_eq!(decision.paths(), ["/home/kyle"]);
assert_eq!(
@@ -103,7 +106,7 @@ fn a_deny_grant_was_added_while_the_approval_waited() {
assert_eq!(denial.grant.as_deref(), Some("no-notes"));
assert_eq!(
denial.grant_sha256,
Some(proto::sha256(b"no-notes").unwrap())
Some(bxcore::sha256(b"no-notes").unwrap())
);
}
+1 -1
View File
@@ -10,7 +10,7 @@ use brokerd::args::{ToolArgs, ToolName};
use brokerd::policy::{Decision, Outcome, SessionState, decide};
use brokerd::runner::{Mount, REFUSING, Refusing, RunError, RunOutput, run};
use build::{grant, now, read, request, set};
use proto::{DataClass, Mode, ToolRequest, ToolResponse};
use bxcore::{DataClass, Mode, ToolRequest, ToolResponse};
use runtime::Recording;
fn allowed(grants: Vec<build::Build>, request: ToolRequest) -> Decision {
+9 -5
View File
@@ -11,7 +11,7 @@ use std::time::{Duration, Instant};
use brokerd::audit::RECOVERED_NOTICE;
use brokerd::runner::REFUSING;
use proto::{
use bxcore::{
AuditEvent, CallId, DenyReason, Empty, Envelope, ErrorCode, Message, PROTOCOL_VERSION,
ResultStatus, SessionId, ToolRequest, ToolResponse,
};
@@ -100,7 +100,11 @@ impl Home {
.flat_map(|n| {
let text = std::fs::read_to_string(dir.join(n)).unwrap();
text.lines()
.map(|l| serde_json::from_str::<proto::AuditRecord>(l).unwrap().event)
.map(|l| {
serde_json::from_str::<bxcore::AuditRecord>(l)
.unwrap()
.event
})
.collect::<Vec<_>>()
})
.collect()
@@ -143,10 +147,10 @@ fn exchange(socket: &Path, id: u64, msg: Message) -> Vec<Envelope> {
r#final: true,
msg,
};
proto::write_frame(&mut stream, &env).unwrap();
bxcore::write_frame(&mut stream, &env).unwrap();
let mut frames = Vec::new();
loop {
let env = proto::read_frame(&mut stream).unwrap();
let env = bxcore::read_frame(&mut stream).unwrap();
let last = env.r#final;
frames.push(env);
if last {
@@ -296,7 +300,7 @@ fn an_approval_nobody_answers_expires() {
fn copy_case(home: &Home, case: &str, only: &[&str]) {
let from = format!(
"{}/../proto/tests/fixtures/audit/{case}",
"{}/../bxcore/tests/fixtures/audit/{case}",
env!("CARGO_MANIFEST_DIR")
);
std::fs::create_dir_all(home.path("audit")).unwrap();
+1 -1
View File
@@ -58,7 +58,7 @@ fn a_break_is_accepted_and_the_next_plain_start_serves() {
std::fs::create_dir_all(&audit).unwrap();
std::fs::create_dir_all(dir.path().join("grants")).unwrap();
let fixture =
Path::new(env!("CARGO_MANIFEST_DIR")).join("../proto/tests/fixtures/audit/changed-byte");
Path::new(env!("CARGO_MANIFEST_DIR")).join("../bxcore/tests/fixtures/audit/changed-byte");
// The damage is in the first file; an ordinary start checks only the latest, so copy that one
// alone, as `audit_startup.rs` does.
std::fs::copy(
+2 -2
View File
@@ -10,11 +10,11 @@ use std::path::Path;
use std::process::{Child, Command, Stdio};
use std::time::{Duration, Instant};
use fake_podman::{Fake, IMAGE, serial};
use proto::{
use bxcore::{
CallId, DataClass, Envelope, Message, PROTOCOL_VERSION, SessionId, ToolRequest, ToolResponse,
read_frame, write_frame,
};
use fake_podman::{Fake, IMAGE, serial};
struct Running(Child);
+1 -1
View File
@@ -5,7 +5,7 @@ mod tmp;
use brokerd::policy::{Label, SessionState};
use brokerd::state::{RUNBOOK, StateError, StateStore};
use proto::{DataClass, SessionId};
use bxcore::{DataClass, SessionId};
use std::os::unix::fs::PermissionsExt;
use tmp::TempDir;
+4 -4
View File
@@ -6,7 +6,7 @@ use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU32, Ordering};
use proto::{AuditEvent, CallId, DataClass, DecisionRecord, SessionId, Timestamp};
use bxcore::{AuditEvent, CallId, DataClass, DecisionRecord, SessionId, Timestamp};
pub const D1: &str = "2026-09-17.jsonl";
pub const D2: &str = "2026-09-18.jsonl";
@@ -28,14 +28,14 @@ impl TempDir {
TempDir { path }
}
/// A copy of the fixture log `case` from `crates/proto/tests/fixtures/audit/`. With `only`,
/// A copy of the fixture log `case` from `crates/bxcore/tests/fixtures/audit/`. With `only`,
/// just those files: damage in an older file is not seen by an ordinary start, so tests of
/// the startup check copy the damaged file alone.
pub fn case(case: &str, only: Option<&[&str]>) -> TempDir {
let dir = TempDir::unmade(case);
std::fs::create_dir_all(&dir.path).unwrap();
let from = format!(
"{}/../proto/tests/fixtures/audit/{case}",
"{}/../bxcore/tests/fixtures/audit/{case}",
env!("CARGO_MANIFEST_DIR")
);
let mut copied = 0;
@@ -88,7 +88,7 @@ pub fn denied(call: u64) -> AuditEvent {
tool: "read_file".to_string(),
arguments: r#"{"path":"/etc/hosts"}"#.to_string(),
outcome: DecisionRecord::Denied {
reason: proto::DenyReason::NoGrant,
reason: bxcore::DenyReason::NoGrant,
},
grant: None,
grant_sha256: None,
+2 -2
View File
@@ -6,7 +6,7 @@
use brokerd::grants::{GrantSet, LoadedGrant};
use brokerd::policy::{Ask, Decision, Denial, Outcome, SessionState};
use proto::{
use bxcore::{
CallId, Constraints, DataClass, DenyReason, Grant, Mode, SessionId, Timestamp, ToolRequest,
};
@@ -39,7 +39,7 @@ pub fn grant(id: &str, tool: &str, mode: Mode) -> Build {
constraints: Constraints::default(),
},
// Stands in for the file's hash, and differs from grant to grant.
sha256: proto::sha256(id.as_bytes()).unwrap(),
sha256: bxcore::sha256(id.as_bytes()).unwrap(),
})
}
+3 -3
View File
@@ -11,7 +11,7 @@ use std::sync::Arc;
use std::time::Duration;
use brokerd::broker::{self, Broker};
use proto::{Envelope, Message, PROTOCOL_VERSION, ToolRequest};
use bxcore::{Envelope, Message, PROTOCOL_VERSION, ToolRequest};
use crate::rig::Rig;
use crate::runtime::{Recording, Shared};
@@ -49,7 +49,7 @@ pub fn open(
r#final: true,
msg,
};
proto::write_frame(&mut client, &env).unwrap();
bxcore::write_frame(&mut client, &env).unwrap();
client
}
@@ -60,7 +60,7 @@ pub fn next(stream: &mut UnixStream) -> Envelope {
let peer_closed = cfg!(target_vendor = "apple") && e.raw_os_error() == Some(22);
assert!(peer_closed, "set_read_timeout: {e}");
}
proto::read_frame(stream).unwrap()
bxcore::read_frame(stream).unwrap()
}
/// Sends a tool request to `broker::handle` and reads every frame up to the final one.
+5 -2
View File
@@ -8,7 +8,7 @@ use std::path::{Path, PathBuf};
use std::sync::mpsc::{self, Receiver};
use std::time::Duration;
use proto::{
use bxcore::{
ApprovalPosted, ApprovalReply, Envelope, ErrorCode, GatewayOutcome, Message, PROTOCOL_VERSION,
PendingApproval, WireError, read_frame, write_frame,
};
@@ -141,7 +141,10 @@ impl Conn {
/// Did the courier close the connection within `wait`, without sending anything?
pub fn closed_within(&mut self, wait: Duration) -> bool {
self.stream.set_read_timeout(Some(wait)).unwrap();
matches!(read_frame(&mut self.stream), Err(proto::FrameError::Closed))
matches!(
read_frame(&mut self.stream),
Err(bxcore::FrameError::Closed)
)
}
pub fn close(self) {
+2 -2
View File
@@ -10,7 +10,7 @@
use brokerd::grants::LoadedGrant;
use brokerd::policy::SessionState;
use proto::{
use bxcore::{
CallId, Constraints, DataClass, DenyReason, Grant, Mode, SessionId, Timestamp, ToolRequest,
};
@@ -119,7 +119,7 @@ pub fn some_grant(rng: &mut Rng, id: usize) -> LoadedGrant {
secret: None,
constraints,
},
sha256: proto::sha256(format!("file {id}").as_bytes()).unwrap(),
sha256: bxcore::sha256(format!("file {id}").as_bytes()).unwrap(),
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ use brokerd::audit::Writer;
use brokerd::config::{Approvals, Config, Paths, Sockets};
use brokerd::ledger::Ledger;
use brokerd::state::StateStore;
use proto::{AuditEvent, AuditRecord, CallId, SessionId, ToolRequest};
use bxcore::{AuditEvent, AuditRecord, CallId, SessionId, ToolRequest};
use crate::sink::{Flaky, Lines, Switch};
use crate::tmp::TempDir;
+1 -1
View File
@@ -9,7 +9,7 @@ use std::sync::{Arc, Mutex};
use brokerd::audit::{AuditError, Writer};
use brokerd::ledger::AuditSink;
use proto::{AuditEvent, Timestamp};
use bxcore::{AuditEvent, Timestamp};
/// Switches shared between a test and its `Flaky` sink.
#[derive(Clone, Default)]