runtime: simplify workdir layout
This commit is contained in:
parent
6b824d9018
commit
1d64618b4a
|
|
@ -1703,11 +1703,7 @@ mod tests {
|
||||||
runtime_base: &std::path::Path,
|
runtime_base: &std::path::Path,
|
||||||
working_directory_id: &str,
|
working_directory_id: &str,
|
||||||
) -> PathBuf {
|
) -> PathBuf {
|
||||||
runtime_base
|
runtime_base.join(working_directory_id).join("checkout")
|
||||||
.join("working-directories")
|
|
||||||
.join(working_directory_id)
|
|
||||||
.join("root")
|
|
||||||
.join("repo-main")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -2008,7 +2004,7 @@ mod tests {
|
||||||
let error = runtime.create_worker(request).unwrap_err();
|
let error = runtime.create_worker(request).unwrap_err();
|
||||||
|
|
||||||
assert!(format!("{error:?}").contains("spawn failed"));
|
assert!(format!("{error:?}").contains("spawn failed"));
|
||||||
let working_directories_root = runtime_base.path().join("working-directories");
|
let working_directories_root = runtime_base.path();
|
||||||
let remaining_entries = fs::read_dir(working_directories_root)
|
let remaining_entries = fs::read_dir(working_directories_root)
|
||||||
.map(|entries| entries.count())
|
.map(|entries| entries.count())
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use std::process::Command;
|
||||||
use std::sync::atomic::{AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicU64, Ordering};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
const WORKING_DIRECTORIES_DIR: &str = "working-directories";
|
const CHECKOUT_DIR: &str = "checkout";
|
||||||
const MATERIALIZATION_RECORD: &str = "materialization.json";
|
const MATERIALIZATION_RECORD: &str = "materialization.json";
|
||||||
static NEXT_WORKING_DIRECTORY_SEQUENCE: AtomicU64 = AtomicU64::new(0);
|
static NEXT_WORKING_DIRECTORY_SEQUENCE: AtomicU64 = AtomicU64::new(0);
|
||||||
|
|
||||||
|
|
@ -200,9 +200,7 @@ impl LocalGitWorktreeMaterializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn working_directory_root(&self, working_directory_id: &str) -> PathBuf {
|
fn working_directory_root(&self, working_directory_id: &str) -> PathBuf {
|
||||||
self.runtime_root
|
self.runtime_root.join(working_directory_id)
|
||||||
.join(WORKING_DIRECTORIES_DIR)
|
|
||||||
.join(working_directory_id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn corrupted_status(&self, working_directory_id: &str) -> WorkingDirectoryStatus {
|
fn corrupted_status(&self, working_directory_id: &str) -> WorkingDirectoryStatus {
|
||||||
|
|
@ -346,9 +344,7 @@ impl LocalGitWorktreeMaterializer {
|
||||||
.filter(|value| !value.is_empty());
|
.filter(|value| !value.is_empty());
|
||||||
|
|
||||||
let working_directory_root = self.working_directory_root(&working_directory_id);
|
let working_directory_root = self.working_directory_root(&working_directory_id);
|
||||||
let worktree_root = working_directory_root
|
let worktree_root = working_directory_root.join(CHECKOUT_DIR);
|
||||||
.join("root")
|
|
||||||
.join(sanitize_path_component(&request.repository.id));
|
|
||||||
if worktree_root.exists() {
|
if worktree_root.exists() {
|
||||||
return Err(WorkingDirectoryDiagnostic::new(
|
return Err(WorkingDirectoryDiagnostic::new(
|
||||||
"working_directory_exists",
|
"working_directory_exists",
|
||||||
|
|
@ -455,8 +451,7 @@ impl WorkingDirectoryMaterializer for LocalGitWorktreeMaterializer {
|
||||||
fn list_working_directories(
|
fn list_working_directories(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<Vec<WorkingDirectoryStatus>, WorkingDirectoryDiagnostic> {
|
) -> Result<Vec<WorkingDirectoryStatus>, WorkingDirectoryDiagnostic> {
|
||||||
let root = self.runtime_root.join(WORKING_DIRECTORIES_DIR);
|
let entries = match fs::read_dir(&self.runtime_root) {
|
||||||
let entries = match fs::read_dir(&root) {
|
|
||||||
Ok(entries) => entries,
|
Ok(entries) => entries,
|
||||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(Vec::new()),
|
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(Vec::new()),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
|
@ -800,6 +795,17 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert!(binding.root.starts_with(runtime_root.path()));
|
assert!(binding.root.starts_with(runtime_root.path()));
|
||||||
|
assert_eq!(
|
||||||
|
binding.working_directory_root(),
|
||||||
|
runtime_root
|
||||||
|
.path()
|
||||||
|
.join(&binding.working_directory.id)
|
||||||
|
.as_path()
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
binding.root(),
|
||||||
|
binding.working_directory_root().join(CHECKOUT_DIR)
|
||||||
|
);
|
||||||
assert!(binding.root.join("README.md").exists());
|
assert!(binding.root.join("README.md").exists());
|
||||||
let branch = git_stdout(binding.root(), ["branch", "--show-current"]).unwrap();
|
let branch = git_stdout(binding.root(), ["branch", "--show-current"]).unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
|
|
|
||||||
|
|
@ -323,7 +323,7 @@ Deno.test("projectConsole shows Grep query and caps result preview to five entri
|
||||||
|
|
||||||
Deno.test("projectConsole keeps Grep error detail in the body", () => {
|
Deno.test("projectConsole keeps Grep error detail in the body", () => {
|
||||||
const message =
|
const message =
|
||||||
"Tool execution failed: Invalid argument: path is outside allowed scope: /home/hare/.yoi/workdirs/working-directories/0019f5bce74f1000000/root/main/ghq.local/github/openai/codex";
|
"Tool execution failed: Invalid argument: path is outside allowed scope: /home/hare/.yoi/workdirs/0019f5bce74f1000000/checkout/ghq.local/github/openai/codex";
|
||||||
const projection = projectConsole([
|
const projection = projectConsole([
|
||||||
{
|
{
|
||||||
eventId: "74",
|
eventId: "74",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user