feat: profile解決とmodel catalogを更新
This commit is contained in:
@@ -8,17 +8,10 @@ use std::path::PathBuf;
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(tag = "kind", content = "value", rename_all = "snake_case")]
|
||||
pub enum ProfileSelector {
|
||||
RuntimeDefault,
|
||||
Builtin(String),
|
||||
Named(String),
|
||||
}
|
||||
|
||||
impl Default for ProfileSelector {
|
||||
fn default() -> Self {
|
||||
Self::RuntimeDefault
|
||||
}
|
||||
}
|
||||
|
||||
/// Runtime fetch/caching metadata for a Backend-authored Decodal profile source archive.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ProfileSourceArchiveHttpRef {
|
||||
|
||||
@@ -353,7 +353,6 @@ pub(crate) fn validate_profile_selector(
|
||||
bundle_id: Option<&str>,
|
||||
) -> Result<(), RuntimeError> {
|
||||
match selector {
|
||||
ProfileSelector::RuntimeDefault => Ok(()),
|
||||
ProfileSelector::Builtin(value) | ProfileSelector::Named(value) => {
|
||||
if value.trim().is_empty() {
|
||||
Err(RuntimeError::InvalidProfileSelector {
|
||||
@@ -544,7 +543,6 @@ fn declaration_sort_key(declaration: &ConfigDeclaration) -> String {
|
||||
|
||||
fn profile_sort_key(selector: &ProfileSelector) -> String {
|
||||
match selector {
|
||||
ProfileSelector::RuntimeDefault => "runtime_default".to_string(),
|
||||
ProfileSelector::Builtin(value) => format!("builtin\0{value}"),
|
||||
ProfileSelector::Named(value) => format!("named\0{value}"),
|
||||
}
|
||||
|
||||
@@ -1808,9 +1808,9 @@ mod ws_tests {
|
||||
}
|
||||
|
||||
fn ws_create_request() -> CreateWorkerRequest {
|
||||
let bundle = ws_test_bundle(ProfileSelector::RuntimeDefault);
|
||||
let bundle = ws_test_bundle(ProfileSelector::Builtin("builtin:companion".to_string()));
|
||||
CreateWorkerRequest {
|
||||
profile: ProfileSelector::RuntimeDefault,
|
||||
profile: ProfileSelector::Builtin("builtin:companion".to_string()),
|
||||
display_name: None,
|
||||
profile_source: crate::catalog::ProfileSourceArchiveSource::Http {
|
||||
location: crate::catalog::ProfileSourceArchiveHttpRef {
|
||||
@@ -1845,7 +1845,9 @@ mod ws_tests {
|
||||
Runtime::with_execution_backend(RuntimeOptions::default(), Arc::new(WsBackend))
|
||||
.unwrap();
|
||||
runtime
|
||||
.store_config_bundle(ws_test_bundle(ProfileSelector::RuntimeDefault))
|
||||
.store_config_bundle(ws_test_bundle(ProfileSelector::Builtin(
|
||||
"builtin:companion".to_string(),
|
||||
)))
|
||||
.unwrap();
|
||||
let worker = runtime
|
||||
.create_worker_scoped(
|
||||
|
||||
@@ -91,9 +91,6 @@ fn build_runtime(config: &ProcessConfig) -> Result<Runtime, ProcessError> {
|
||||
),
|
||||
));
|
||||
}
|
||||
if let Some(profile) = config.profile.clone() {
|
||||
factory = factory.with_profile(profile);
|
||||
}
|
||||
let backend = Arc::new(
|
||||
WorkerRuntimeExecutionBackend::new(factory)
|
||||
.map_err(ProcessError::WorkerAdapter)?
|
||||
@@ -171,9 +168,6 @@ where
|
||||
"--backend-resource-token" => {
|
||||
config.backend_resource_token = Some(take_value(&flag, inline_value, &mut args)?);
|
||||
}
|
||||
"--profile" => {
|
||||
config.profile = Some(take_value(&flag, inline_value, &mut args)?);
|
||||
}
|
||||
"--store" => {
|
||||
let value = take_value(&flag, inline_value, &mut args)?;
|
||||
if !matches!(value.as_str(), "fs" | "fs-store") {
|
||||
@@ -286,7 +280,6 @@ struct ProcessConfig {
|
||||
no_store: bool,
|
||||
backend_resource_endpoint: Option<String>,
|
||||
backend_resource_token: Option<String>,
|
||||
profile: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@@ -308,7 +301,6 @@ impl ProcessConfig {
|
||||
no_store: false,
|
||||
backend_resource_endpoint: None,
|
||||
backend_resource_token: None,
|
||||
profile: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -804,7 +796,6 @@ Browsers must not connect to this Runtime process directly.
|
||||
Options:
|
||||
--bind <ADDR> Bind socket address (default: 127.0.0.1:38800)
|
||||
--display-name <NAME> Runtime display name
|
||||
--profile <SELECTOR> Force spawned Workers to use a Profile selector
|
||||
--fs-root <PATH> Filesystem-backed storage root (default: user data dir)
|
||||
--fs-worker-dir <PATH> Worker storage directory (default: <fs-root>/worker)
|
||||
--fs-runtime-dir <PATH> Runtime catalog directory (default: <fs-root>/runtime)
|
||||
@@ -852,6 +843,7 @@ mod tests {
|
||||
assert!(parse_args(["--worker-store-dir", "/tmp/sessions"]).is_err());
|
||||
assert!(parse_args(["--worker-metadata-dir", "/tmp/metadata"]).is_err());
|
||||
assert!(parse_args(["--worker-runtime-base-dir", "/tmp/runtime"]).is_err());
|
||||
assert!(parse_args(["--profile", "builtin:coder"]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -866,8 +858,6 @@ mod tests {
|
||||
"127.0.0.1:0",
|
||||
"--display-name",
|
||||
"Runtime Alpha",
|
||||
"--profile",
|
||||
"builtin:coder",
|
||||
"--local-token-env",
|
||||
"TEST_RUNTIME_TOKEN",
|
||||
]);
|
||||
@@ -881,8 +871,6 @@ mod tests {
|
||||
"127.0.0.1:0",
|
||||
"--display-name",
|
||||
"Runtime Alpha",
|
||||
"--profile",
|
||||
"builtin:coder",
|
||||
"--local-token-env",
|
||||
"TEST_RUNTIME_TOKEN",
|
||||
])
|
||||
@@ -894,7 +882,6 @@ mod tests {
|
||||
|
||||
assert_eq!(config.http.bind_addr, "127.0.0.1:0".parse().unwrap());
|
||||
assert_eq!(config.http.display_name.as_deref(), Some("Runtime Alpha"));
|
||||
assert_eq!(config.profile.as_deref(), Some("builtin:coder"));
|
||||
assert_eq!(config.http.local_token.as_deref(), Some("secret-token"));
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,6 @@ pub struct ProfileRuntimeWorkerFactory {
|
||||
profile_base_dir: PathBuf,
|
||||
store_dir: Option<PathBuf>,
|
||||
worker_metadata_dir: Option<PathBuf>,
|
||||
profile: Option<String>,
|
||||
runtime_base_dir: RuntimeArtifactRoot,
|
||||
resource_client: Option<Arc<dyn BackendResourceClient>>,
|
||||
profile_archive_cache: Arc<ProfileSourceArchiveCache>,
|
||||
@@ -118,7 +117,6 @@ impl ProfileRuntimeWorkerFactory {
|
||||
profile_base_dir,
|
||||
store_dir: None,
|
||||
worker_metadata_dir: None,
|
||||
profile: None,
|
||||
runtime_base_dir: RuntimeArtifactRoot::owned(),
|
||||
resource_client: None,
|
||||
profile_archive_cache: Arc::new(ProfileSourceArchiveCache::default()),
|
||||
@@ -135,13 +133,6 @@ impl ProfileRuntimeWorkerFactory {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the profile selector used for Runtime-created Workers. When unset,
|
||||
/// normal default profile discovery is used.
|
||||
pub fn with_profile(mut self, profile: impl Into<String>) -> Self {
|
||||
self.profile = Some(profile.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_runtime_base_dir(mut self, runtime_base_dir: impl Into<PathBuf>) -> Self {
|
||||
self.runtime_base_dir = RuntimeArtifactRoot::External(runtime_base_dir.into());
|
||||
self
|
||||
@@ -184,37 +175,27 @@ impl ProfileRuntimeWorkerFactory {
|
||||
|
||||
fn runtime_profile_value(
|
||||
profile: &crate::catalog::ProfileSelector,
|
||||
) -> Option<std::borrow::Cow<'_, str>> {
|
||||
) -> std::borrow::Cow<'_, str> {
|
||||
match profile {
|
||||
crate::catalog::ProfileSelector::RuntimeDefault => None,
|
||||
crate::catalog::ProfileSelector::Named(name) => {
|
||||
Some(std::borrow::Cow::Borrowed(name.as_str()))
|
||||
std::borrow::Cow::Borrowed(name.as_str())
|
||||
}
|
||||
crate::catalog::ProfileSelector::Builtin(name) => {
|
||||
if name.starts_with("builtin:") {
|
||||
Some(std::borrow::Cow::Borrowed(name.as_str()))
|
||||
std::borrow::Cow::Borrowed(name.as_str())
|
||||
} else {
|
||||
Some(std::borrow::Cow::Owned(format!("builtin:{name}")))
|
||||
std::borrow::Cow::Owned(format!("builtin:{name}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn runtime_profile_for_request<'a>(
|
||||
&'a self,
|
||||
request: &'a CreateWorkerRequest,
|
||||
) -> Option<std::borrow::Cow<'a, str>> {
|
||||
if let Some(profile) = self.profile.as_deref() {
|
||||
return Some(std::borrow::Cow::Borrowed(profile));
|
||||
}
|
||||
fn runtime_profile_for_request(request: &CreateWorkerRequest) -> std::borrow::Cow<'_, str> {
|
||||
Self::runtime_profile_value(&request.profile)
|
||||
}
|
||||
|
||||
fn runtime_profile<'a>(
|
||||
&'a self,
|
||||
request: &'a WorkerExecutionSpawnRequest,
|
||||
) -> Option<std::borrow::Cow<'a, str>> {
|
||||
self.runtime_profile_for_request(&request.request)
|
||||
fn runtime_profile(request: &WorkerExecutionSpawnRequest) -> std::borrow::Cow<'_, str> {
|
||||
Self::runtime_profile_for_request(&request.request)
|
||||
}
|
||||
|
||||
fn restore_fallback_manifest(
|
||||
@@ -368,7 +349,7 @@ impl RuntimeWorkerFactory for ProfileRuntimeWorkerFactory {
|
||||
request: WorkerExecutionSpawnRequest,
|
||||
) -> Result<WorkerHandle, String> {
|
||||
let worker_name = Self::runtime_worker_name(&request);
|
||||
let profile = self.runtime_profile(&request);
|
||||
let profile = Self::runtime_profile(&request);
|
||||
let has_local_filesystem = request.working_directory.is_some();
|
||||
let worker_root = request
|
||||
.working_directory
|
||||
@@ -388,7 +369,7 @@ impl RuntimeWorkerFactory for ProfileRuntimeWorkerFactory {
|
||||
let workspace_backend_ref =
|
||||
RuntimeWorkspaceBackendRef::from_worker_request(&request.request);
|
||||
let workspace_context = workspace_backend_ref.worker_context();
|
||||
let selector = profile.as_deref().unwrap_or("builtin:default");
|
||||
let selector = profile.as_ref();
|
||||
let archive = self
|
||||
.resolve_profile_source_archive(&request.request.profile_source)
|
||||
.await?;
|
||||
@@ -1421,7 +1402,7 @@ mod tests {
|
||||
},
|
||||
},
|
||||
profiles: vec![crate::config_bundle::ConfigProfileDescriptor {
|
||||
selector: ProfileSelector::RuntimeDefault,
|
||||
selector: ProfileSelector::Builtin("builtin:companion".to_string()),
|
||||
label: Some("adapter-test".to_string()),
|
||||
}],
|
||||
declarations: Vec::new(),
|
||||
@@ -1457,7 +1438,7 @@ mod tests {
|
||||
fn create_request(_name: &str) -> CreateWorkerRequest {
|
||||
let bundle = test_bundle();
|
||||
CreateWorkerRequest {
|
||||
profile: ProfileSelector::RuntimeDefault,
|
||||
profile: ProfileSelector::Builtin("builtin:companion".to_string()),
|
||||
display_name: None,
|
||||
profile_source: crate::catalog::ProfileSourceArchiveSource::Embedded {
|
||||
archive: bundle.profile_source_archive.clone().unwrap(),
|
||||
@@ -1654,15 +1635,15 @@ mod tests {
|
||||
ProfileRuntimeWorkerFactory::runtime_profile_value(
|
||||
&crate::catalog::ProfileSelector::Builtin("coder".to_string())
|
||||
)
|
||||
.as_deref(),
|
||||
Some("builtin:coder")
|
||||
.as_ref(),
|
||||
"builtin:coder"
|
||||
);
|
||||
assert_eq!(
|
||||
ProfileRuntimeWorkerFactory::runtime_profile_value(
|
||||
&crate::catalog::ProfileSelector::Builtin("builtin:coder".to_string())
|
||||
)
|
||||
.as_deref(),
|
||||
Some("builtin:coder")
|
||||
.as_ref(),
|
||||
"builtin:coder"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user