fix: restore workers with remote workdir attachments

This commit is contained in:
2026-09-01 20:41:37 +09:00
parent d1e8a827c2
commit 816fa96e07
3 changed files with 113 additions and 9 deletions
+41 -8
View File
@@ -1909,16 +1909,18 @@ impl WorkspaceApi {
.list_worker_workdir_links(&self.config.workspace_id, worker)?
.into_iter()
.find(|link| link.unlinked_at.is_none())
&& let Some(access) = repository_access_request_for_workdir(
{
let workdir_runtime_id = registered_workdir_runtime_id(self, &link.workdir_id)?;
if let Some(access) = repository_access_request_for_workdir(
self,
&worker.runtime_id,
&workdir_runtime_id,
&link.workdir_id,
&format!("worker-restore:{}", WorkerId::now_v7()),
)?
{
self.runtime
.authorize_working_directory_repository_access(&worker.runtime_id, access)
.map_err(RuntimeRegistryError::into_error)?;
)? {
self.runtime
.authorize_working_directory_repository_access(&workdir_runtime_id, access)
.map_err(RuntimeRegistryError::into_error)?;
}
}
let binding = self
.runtime
@@ -25010,7 +25012,7 @@ mod tests {
)
.await
.unwrap();
let app = build_inner_router(api);
let app = build_inner_router(api.clone());
let runtimes = get_json(app.clone(), "/api/runtimes").await;
let embedded_summary = runtimes["items"]
@@ -25065,6 +25067,37 @@ mod tests {
"embedded_worker_runtime"
);
let workdir_id = "external-workdir";
api.store
.upsert_workdir_registry(&WorkdirRegistryRecord {
workspace_id: TEST_WORKSPACE_ID.to_string(),
workdir_id: workdir_id.to_string(),
runtime_id: "external-workdir-runtime".to_string(),
repository_id: "main".to_string(),
creation_selector: None,
creation_ref: None,
creation_tree: None,
current_selector: None,
current_ref: None,
current_tree: None,
observed_at_epoch_seconds: None,
materialization_status: "present".to_string(),
cleanliness: "clean".to_string(),
created_at: "1".to_string(),
updated_at: "1".to_string(),
})
.unwrap();
api.store
.attach_worker_workdir(&WorkerWorkdirLinkRecord {
workspace_id: TEST_WORKSPACE_ID.to_string(),
worker: RuntimeWorkerRef::new("embedded-worker-runtime", &worker_id),
workdir_id: workdir_id.to_string(),
role: "attachment".to_string(),
linked_at: "2".to_string(),
unlinked_at: None,
})
.unwrap();
let worker = get_json(
app.clone(),
&format!("/api/runtimes/embedded-worker-runtime/workers/{worker_id}"),