feat(aws): phase 6 project settings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-15 21:29:29 -08:00
1 parent 6497dd84e9
commit 34a6edd413
10 files changed
+155 -12

No files matched your search

+2 -2
View File
@@ -2304,7 +2304,7 @@ mod environment {
let tail1: Vec<&String> = log1.iter().filter(|l| l.contains("entrypoint: stopping") || l.contains("wip") || l.contains("WIP")).collect();
eprintln!("RESULT task 1 stop log lines: {tail1:#?}");
assert!(log1.iter().any(|l| l.contains("entrypoint: stopping (sigterm) — pushing work in progress")), "{log1:#?}");
store.set_aws_runtime(&id, None, current(&store).aws.unwrap().access_point_id, Some(revision1.clone())).unwrap();
store.set_aws_runtime(&id, None, current(&store).aws.unwrap().access_point_id, Some(revision1.clone()), None).unwrap();
// ── start 2, unchanged; idle stop is at its minimum ──
let t3 = std::time::Instant::now();
@@ -2388,7 +2388,7 @@ mod environment {
// ── remove: the task, the secret and (data discarded) the access
// point; the task definition is left (R8) ──
store.set_aws_runtime(&id, None, aws2.access_point_id.clone(), aws2.task_definition_arn.clone()).unwrap();
store.set_aws_runtime(&id, None, aws2.access_point_id.clone(), aws2.task_definition_arn.clone(), aws2.workspace_access_point_id.clone()).unwrap();
// Every step runs even when one fails (the failures are
// reported together), so check them all before the result.
let removed = host.remove_aws_resources(&current(&store), &settings, true).await;
+3 -2
View File
@@ -184,6 +184,7 @@ fn payload_map(
match storage {
StorageMode::Ephemeral => "ephemeral",
StorageMode::Hybrid => "hybrid",
StorageMode::Efs => "efs", // Task 3
}
.into(),
);
@@ -327,7 +328,7 @@ pub fn task_definition_request(plan: &WorkspacePlan) -> RegisterTaskDefinitionIn
fn build_request(plan: &WorkspacePlan) -> RegisterTaskDefinitionInput {
const BUILT: &str = "every required field is set";
let hybrid = match (&plan.storage, &plan.file_system_id, &plan.access_point_id) {
(StorageMode::Hybrid, Some(fs), Some(ap)) => Some((fs, ap)),
(StorageMode::Hybrid | StorageMode::Efs, Some(fs), Some(ap)) => Some((fs, ap)), // Task 3: Efs adds /workspace
_ => None,
};
@@ -654,7 +655,7 @@ pub async fn prepare_workspace<W: WorkspaceApi>(
// Hybrid: the user's own file system, from their onboarding.
let (file_system_id, access_point_id) = match cfg.storage {
StorageMode::Ephemeral => (None, None),
StorageMode::Hybrid => {
StorageMode::Hybrid | StorageMode::Efs => { // Task 3: Efs adds the workspace access point
let token = user_file_system_token(&env.name, &ok);
let fs = api
.find_file_system(&token)
+23 -2
View File
@@ -1191,6 +1191,7 @@ fn restore_store_owned_fields(project: &mut Project, stored: &Project) {
aws.task_arn = s.and_then(|a| a.task_arn.clone());
aws.access_point_id = s.and_then(|a| a.access_point_id.clone());
aws.task_definition_arn = s.and_then(|a| a.task_definition_arn.clone());
aws.workspace_access_point_id = s.and_then(|a| a.workspace_access_point_id.clone());
}
}
@@ -1226,7 +1227,10 @@ fn validate_aws_update(
// connection's account and region; moving the project would orphan them.
if moved
&& stored.aws.as_ref().is_some_and(|a| {
a.task_arn.is_some() || a.access_point_id.is_some() || a.task_definition_arn.is_some()
a.task_arn.is_some()
|| a.access_point_id.is_some()
|| a.workspace_access_point_id.is_some()
|| a.task_definition_arn.is_some()
})
{
return Err(
@@ -1467,6 +1471,7 @@ async fn start_project_container_locked(
Some(task_arn),
access_point_id,
Some(task_definition_arn),
project.aws.as_ref().and_then(|a| a.workspace_access_point_id.clone()), // Task 3: from the start
)?;
}
}
@@ -1585,6 +1590,7 @@ pub async fn stop_project_container(
None,
a.access_point_id.clone(),
a.task_definition_arn.clone(),
a.workspace_access_point_id.clone(),
)?;
}
state.projects_store.set_container_id(&project_id, None)?;
@@ -1695,7 +1701,7 @@ pub async fn remove_aws_resources(
.await?;
state
.projects_store
.set_aws_runtime(&project_id, None, access_point_after_removal(&project, discard_data), None)?;
.set_aws_runtime(&project_id, None, access_point_after_removal(&project, discard_data), None, None)?;
state
.projects_store
.get(&project_id)
@@ -2616,12 +2622,14 @@ mod tests {
sc.task_arn = Some("arn:task".into());
sc.access_point_id = Some("fsap-1".into());
sc.task_definition_arn = Some("arn:td".into());
sc.workspace_access_point_id = Some("fsap-w".into());
stored.aws = Some(sc.clone());
let mut pc = crate::models::AwsWorkspaceConfig::default();
pc.cpu = 2048;
pc.memory_mib = 8192;
pc.task_arn = Some("evil".into());
pc.access_point_id = None;
pc.workspace_access_point_id = None;
payload.aws = Some(pc);
restore_store_owned_fields(&mut payload, &stored);
@@ -2630,6 +2638,7 @@ mod tests {
assert_eq!(a.task_arn, sc.task_arn);
assert_eq!(a.access_point_id, sc.access_point_id);
assert_eq!(a.task_definition_arn, sc.task_definition_arn);
assert_eq!(a.workspace_access_point_id, Some("fsap-w".into()));
assert_eq!(a.cpu, 2048, "the edit itself goes through");
}
@@ -2653,6 +2662,18 @@ mod tests {
p
}
#[test]
fn a_stored_workspace_access_point_blocks_moving_the_host() {
let hosts = vec![host("h1"), host("h2")];
let mut stored = aws_project();
stored.aws.as_mut().unwrap().workspace_access_point_id = Some("fsap-w".into());
let mut moved = stored.clone();
moved.host_id = Some("h2".into());
assert!(validate_aws_update(&stored, &moved, &hosts).unwrap_err().contains("AWS resources"));
stored.aws.as_mut().unwrap().workspace_access_point_id = None;
assert!(validate_aws_update(&stored, &moved, &hosts).is_ok());
}
#[test]
fn host_update_rules() {
let hosts = vec![host("h1")];
+1
View File
@@ -276,6 +276,7 @@ pub fn spawn(
None,
a.access_point_id.clone(),
a.task_definition_arn.clone(),
a.workspace_access_point_id.clone(),
);
}
let id = p.id.clone();
+2
View File
@@ -651,12 +651,14 @@ pub fn record_task(store: &ProjectsStore, project_id: &str, rec: Option<&TaskRec
Some(r.task_arn.clone()),
r.access_point_id.clone().or(stored.access_point_id),
r.task_definition_arn.clone().or(stored.task_definition_arn),
stored.workspace_access_point_id, // Task 3: from the record
),
None => store.set_aws_runtime(
project_id,
None,
stored.access_point_id,
stored.task_definition_arn,
stored.workspace_access_point_id,
),
};
if let Err(e) = res {
+84
View File
@@ -486,6 +486,19 @@ pub enum StorageMode {
Ephemeral,
#[default]
Hybrid,
/// Hybrid plus `/workspace` on EFS (a second access point).
Efs,
}
/// How an AWS project's credentials and files reach the workspace.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "snake_case")]
pub enum SecretsDelivery {
/// In the project's Secrets Manager secret.
#[default]
SecretsManager,
/// Kept out of the secret; the app copies them in after each connect.
CopyAtConnect,
}
/// One git repository cloned into the workspace. `branch: None` means the
@@ -536,8 +549,22 @@ pub struct AwsWorkspaceConfig {
pub access_point_id: Option<String>,
#[serde(default)]
pub task_definition_arn: Option<String>,
/// Store-owned like `access_point_id`: the EFS-mode `/workspace` access point.
#[serde(default)]
pub workspace_access_point_id: Option<String>,
#[serde(default)]
pub secrets_delivery: SecretsDelivery,
/// Run after the clone, as `claude` (AWS only).
#[serde(default)]
pub setup_script: Option<String>,
/// Run the LiteLLM gateway as a sidecar container.
#[serde(default)]
pub gateway_sidecar: bool,
}
/// Largest setup script, in bytes.
pub const MAX_SETUP_SCRIPT_BYTES: usize = 32_768;
impl Default for AwsWorkspaceConfig {
fn default() -> Self {
Self {
@@ -553,6 +580,10 @@ impl Default for AwsWorkspaceConfig {
task_arn: None,
access_point_id: None,
task_definition_arn: None,
workspace_access_point_id: None,
secrets_delivery: SecretsDelivery::default(),
setup_script: None,
gateway_sidecar: false,
}
}
}
@@ -706,6 +737,21 @@ pub fn validate_aws_workspace(cfg: &AwsWorkspaceConfig) -> Result<(), String> {
return Err(format!("Repository folder \"{}\" is used twice", r.folder));
}
}
if let Some(script) = &cfg.setup_script {
if script.len() > MAX_SETUP_SCRIPT_BYTES {
return Err(format!(
"The setup script is {} bytes; the limit is {}",
script.len(),
MAX_SETUP_SCRIPT_BYTES
));
}
if script.contains('\0') {
return Err("The setup script must not contain NUL characters".into());
}
}
if cfg.gateway_sidecar && (cfg.cpu < 1024 || cfg.memory_mib < 2048) {
return Err("The LLM gateway sidecar needs at least 1 vCPU (1024) and 2 GiB (2048 MiB)".into());
}
Ok(())
}
@@ -1342,6 +1388,44 @@ mod tests {
assert!(!off.wip_push_on_stop);
}
#[test]
fn phase6_fields_default_for_old_json_and_efs_round_trips() {
let c: AwsWorkspaceConfig = serde_json::from_str(r#"{"storage":"hybrid","cpu":512}"#).unwrap();
assert_eq!(c.secrets_delivery, SecretsDelivery::SecretsManager);
assert!(!c.gateway_sidecar && c.setup_script.is_none() && c.workspace_access_point_id.is_none());
let e: AwsWorkspaceConfig = serde_json::from_str(r#"{"storage":"efs","secrets_delivery":"copy_at_connect"}"#).unwrap();
assert_eq!(e.storage, StorageMode::Efs);
assert_eq!(e.secrets_delivery, SecretsDelivery::CopyAtConnect);
assert_eq!(serde_json::to_string(&StorageMode::Efs).unwrap(), "\"efs\"");
assert_eq!(serde_json::to_string(&SecretsDelivery::CopyAtConnect).unwrap(), "\"copy_at_connect\"");
let back: AwsWorkspaceConfig = serde_json::from_str(&serde_json::to_string(&e).unwrap()).unwrap();
assert_eq!(back, e);
}
#[test]
fn setup_script_limits() {
let mut c = AwsWorkspaceConfig::default();
c.setup_script = Some("a".repeat(MAX_SETUP_SCRIPT_BYTES));
assert!(validate_aws_workspace(&c).is_ok());
c.setup_script = Some("a".repeat(MAX_SETUP_SCRIPT_BYTES + 1));
assert!(validate_aws_workspace(&c).unwrap_err().contains("limit"));
c.setup_script = Some("echo\0hi".into());
assert!(validate_aws_workspace(&c).unwrap_err().contains("NUL"));
}
#[test]
fn gateway_sidecar_needs_one_vcpu_and_two_gib() {
let mut c = cfg(512, 2048);
c.gateway_sidecar = true;
assert!(validate_aws_workspace(&c).is_err());
c = cfg(1024, 2048);
c.gateway_sidecar = true;
assert!(validate_aws_workspace(&c).is_ok());
c = cfg(256, 2048);
c.gateway_sidecar = true;
assert!(validate_aws_workspace(&c).is_err());
}
#[test]
fn enums_serialize_snake_case_and_is_aws_follows_host_id() {
assert_eq!(serde_json::to_string(&Arch::Arm64).unwrap(), "\"arm64\"");
+6 -4
View File
@@ -448,6 +448,7 @@ impl ProjectsStore {
task_arn: Option<String>,
access_point_id: Option<String>,
task_definition_arn: Option<String>,
workspace_access_point_id: Option<String>,
) -> Result<(), String> {
let mut projects = self.lock();
let p = projects
@@ -461,6 +462,7 @@ impl ProjectsStore {
aws.task_arn = task_arn;
aws.access_point_id = access_point_id;
aws.task_definition_arn = task_definition_arn;
aws.workspace_access_point_id = workspace_access_point_id;
p.updated_at = chrono::Utc::now().to_rfc3339();
self.save(&projects)?;
Ok(())
@@ -885,7 +887,7 @@ mod tests {
let store = store_over(&dir, vec![aws, local]);
store
.set_aws_runtime(&aid, Some("t".into()), Some("ap".into()), Some("td".into()))
.set_aws_runtime(&aid, Some("t".into()), Some("ap".into()), Some("td".into()), Some("wap".into()))
.unwrap();
let a = store.get(&aid).unwrap().aws.unwrap();
assert_eq!(
@@ -896,10 +898,10 @@ mod tests {
serde_json::from_str(&fs::read_to_string(dir.join("projects.json")).unwrap()).unwrap();
assert_eq!(on_disk[0].aws.as_ref().unwrap().task_arn.as_deref(), Some("t"));
store.set_aws_runtime(&aid, None, None, None).unwrap();
store.set_aws_runtime(&aid, None, None, None, None).unwrap();
assert!(store.get(&aid).unwrap().aws.unwrap().task_arn.is_none());
assert!(store.set_aws_runtime(&lid, None, None, None).is_err());
assert!(store.set_aws_runtime("nope", None, None, None).is_err());
assert!(store.set_aws_runtime(&lid, None, None, None, None).is_err());
assert!(store.set_aws_runtime("nope", None, None, None, None).is_err());
fs::remove_dir_all(&dir).ok();
}
}
+20
View File
@@ -1,6 +1,8 @@
import { describe, it, expect } from "vitest";
import {
cleanRepos,
defaultAwsWorkspace,
hasSavedFiles,
environmentSelectable,
memoryError,
memoryOptions,
@@ -59,3 +61,21 @@ describe("awsWorkspace", () => {
expect(environmentSelectable(environment("a", "deploying", true))).toBe(false);
});
});
describe("phase 6 settings", () => {
it("defaults mirror Rust", () => {
const d = defaultAwsWorkspace();
expect([d.secrets_delivery, d.setup_script, d.gateway_sidecar, d.workspace_access_point_id]).toEqual([
"secrets_manager",
null,
false,
null,
]);
});
it("EFS mode and a leftover workspace access point count as saved files", () => {
const aws = defaultAwsWorkspace();
expect(hasSavedFiles({ aws: { ...aws, storage: "efs" } })).toBe(true);
expect(hasSavedFiles({ aws: { ...aws, storage: "ephemeral", workspace_access_point_id: "fsap-w" } })).toBe(true);
expect(hasSavedFiles({ aws: { ...aws, storage: "ephemeral" } })).toBe(false);
});
});
+6 -1
View File
@@ -83,9 +83,13 @@ export function defaultAwsWorkspace(): AwsWorkspaceConfig {
idle_stop_minutes: null,
repos: [],
wip_push_on_stop: true,
secrets_delivery: "secrets_manager",
setup_script: null,
gateway_sidecar: false,
task_arn: null,
access_point_id: null,
task_definition_arn: null,
workspace_access_point_id: null,
};
}
@@ -121,7 +125,8 @@ export function environmentSelectable(env: DetectedEnvironment): boolean {
/** Whether an AWS project may have saved files on EFS (Hybrid now, or an
* access point left from when it was). Ephemeral-only projects have none. */
export function hasSavedFiles(p: Pick<Project, "aws">): boolean {
return p.aws?.storage === "hybrid" || !!p.aws?.access_point_id;
const a = p.aws;
return a?.storage === "hybrid" || a?.storage === "efs" || !!a?.access_point_id || !!a?.workspace_access_point_id;
}
/** Hosts that only mean something on this machine or its Docker bridge. */
+8 -1
View File
@@ -82,7 +82,8 @@ export interface AwsPlacement {
}
export type Arch = "x86_64" | "arm64";
export type StorageMode = "ephemeral" | "hybrid";
export type StorageMode = "ephemeral" | "hybrid" | "efs";
export type SecretsDelivery = "secrets_manager" | "copy_at_connect";
export interface RepoSource {
url: string;
@@ -101,10 +102,16 @@ export interface AwsWorkspaceConfig {
idle_stop_minutes: number | null;
repos: RepoSource[];
wip_push_on_stop: boolean;
secrets_delivery: SecretsDelivery;
/** Run as `claude` after the clone; null = none. At most 32768 bytes. */
setup_script: string | null;
/** Run the LLM gateway as a sidecar (needs 1 vCPU and 2 GiB). */
gateway_sidecar: boolean;
/** Store-owned runtime handles; a save cannot change them. */
task_arn: string | null;
access_point_id: string | null;
task_definition_arn: string | null;
workspace_access_point_id: string | null;
}
/** Where a new project runs: omitted (or all null) = local Docker. An AWS