Merge commit '5670c20a6a50077985168269dfc15a6776c66ba6' into work/T-699-checkout-projection
This commit is contained in:
@@ -735,6 +735,10 @@ pub struct WorkerCompletionsRequest {
|
||||
pub kind: protocol::CompletionKind,
|
||||
#[serde(default)]
|
||||
pub prefix: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub context: Option<protocol::CompletionContext>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub request_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
@@ -743,6 +747,10 @@ pub struct WorkerCompletionsResult {
|
||||
pub worker: RuntimeWorkerRef,
|
||||
pub kind: protocol::CompletionKind,
|
||||
pub prefix: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub context: Option<protocol::CompletionContext>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub request_id: Option<String>,
|
||||
pub entries: Vec<protocol::CompletionEntry>,
|
||||
pub diagnostics: Vec<RuntimeDiagnostic>,
|
||||
}
|
||||
@@ -1327,6 +1335,8 @@ pub trait WorkspaceWorkerRuntime: Send + Sync {
|
||||
worker: RuntimeWorkerRef::new(self.runtime_id().to_string(), worker_id.to_string()),
|
||||
kind: request.kind,
|
||||
prefix: request.prefix,
|
||||
context: request.context,
|
||||
request_id: request.request_id,
|
||||
entries: Vec::new(),
|
||||
diagnostics: vec![diagnostic(
|
||||
"worker_completions_unsupported",
|
||||
@@ -3310,6 +3320,8 @@ impl WorkspaceWorkerRuntime for EmbeddedWorkerRuntime {
|
||||
worker: RuntimeWorkerRef::new(self.runtime_id.clone(), worker_id.to_string()),
|
||||
kind: request.kind,
|
||||
prefix: request.prefix,
|
||||
context: request.context,
|
||||
request_id: request.request_id,
|
||||
entries: Vec::new(),
|
||||
diagnostics: vec![diagnostic(
|
||||
"embedded_worker_execution_unavailable",
|
||||
@@ -3325,6 +3337,8 @@ impl WorkspaceWorkerRuntime for EmbeddedWorkerRuntime {
|
||||
worker: RuntimeWorkerRef::new(self.runtime_id.clone(), worker_id.to_string()),
|
||||
kind: request.kind,
|
||||
prefix: request.prefix,
|
||||
context: request.context,
|
||||
request_id: request.request_id,
|
||||
entries: Vec::new(),
|
||||
diagnostics: vec![diagnostic(
|
||||
"embedded_worker_id_invalid",
|
||||
@@ -3333,14 +3347,18 @@ impl WorkspaceWorkerRuntime for EmbeddedWorkerRuntime {
|
||||
)],
|
||||
};
|
||||
};
|
||||
match self
|
||||
.runtime
|
||||
.worker_completions(&worker_ref, request.kind, &request.prefix)
|
||||
{
|
||||
match self.runtime.worker_completions(
|
||||
&worker_ref,
|
||||
request.kind,
|
||||
&request.prefix,
|
||||
request.context.as_ref(),
|
||||
) {
|
||||
Ok(entries) => WorkerCompletionsResult {
|
||||
worker: RuntimeWorkerRef::new(self.runtime_id.clone(), worker_id.to_string()),
|
||||
kind: request.kind,
|
||||
prefix: request.prefix,
|
||||
context: request.context,
|
||||
request_id: request.request_id,
|
||||
entries,
|
||||
diagnostics: Vec::new(),
|
||||
},
|
||||
@@ -3348,6 +3366,8 @@ impl WorkspaceWorkerRuntime for EmbeddedWorkerRuntime {
|
||||
worker: RuntimeWorkerRef::new(self.runtime_id.clone(), worker_id.to_string()),
|
||||
kind: request.kind,
|
||||
prefix: request.prefix,
|
||||
context: request.context,
|
||||
request_id: request.request_id,
|
||||
entries: Vec::new(),
|
||||
diagnostics: vec![embedded_runtime_diagnostic(&error)],
|
||||
},
|
||||
@@ -5415,9 +5435,13 @@ impl WorkspaceWorkerRuntime for RemoteWorkerRuntime {
|
||||
let request = runtime_api::CompletionRequest {
|
||||
kind: request.kind,
|
||||
prefix: request.prefix,
|
||||
context: request.context,
|
||||
request_id: request.request_id,
|
||||
};
|
||||
let failure_kind = request.kind;
|
||||
let failure_prefix = request.prefix.clone();
|
||||
let failure_context = request.context.clone();
|
||||
let failure_request_id = request.request_id.clone();
|
||||
let worker_id_owned = worker_id.to_string();
|
||||
match self.run_runtime_api(
|
||||
self.request_timeout,
|
||||
@@ -5432,6 +5456,8 @@ impl WorkspaceWorkerRuntime for RemoteWorkerRuntime {
|
||||
worker: RuntimeWorkerRef::new(self.runtime_id.clone(), worker_id.to_string()),
|
||||
kind: response.kind,
|
||||
prefix: response.prefix,
|
||||
context: response.context,
|
||||
request_id: response.request_id,
|
||||
entries: response.entries,
|
||||
diagnostics: Vec::new(),
|
||||
},
|
||||
@@ -5439,6 +5465,8 @@ impl WorkspaceWorkerRuntime for RemoteWorkerRuntime {
|
||||
worker: RuntimeWorkerRef::new(self.runtime_id.clone(), worker_id.to_string()),
|
||||
kind: failure_kind,
|
||||
prefix: failure_prefix,
|
||||
context: failure_context,
|
||||
request_id: failure_request_id,
|
||||
entries: Vec::new(),
|
||||
diagnostics: vec![diagnostic],
|
||||
},
|
||||
@@ -6711,6 +6739,46 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn feature_invocation_and_completion_context_survive_runtime_contract() {
|
||||
let segments = vec![
|
||||
protocol::Segment::FeatureInvoke {
|
||||
invocation: protocol::FeatureInvocation {
|
||||
invocation_id: "stable-request".into(),
|
||||
identity: protocol::FeatureInvocationIdentity("builtin:test/prepare".into()),
|
||||
name: "prepare".into(),
|
||||
arguments: vec![protocol::InvocationArgumentValue {
|
||||
name: "path".into(),
|
||||
value: protocol::InvocationValue::String("資料/a b".into()),
|
||||
}],
|
||||
},
|
||||
},
|
||||
protocol::Segment::text(" subsequent prose"),
|
||||
];
|
||||
let input = EmbeddedWorkerInput {
|
||||
kind: EmbeddedWorkerInputKind::User,
|
||||
content: protocol::Segment::flatten_to_text(&segments),
|
||||
submission_request_id: Some("submit-request".into()),
|
||||
segments: Some(segments),
|
||||
};
|
||||
let wire: runtime_api::WorkerInput = runtime_contract_convert(input.clone()).unwrap();
|
||||
let restored: EmbeddedWorkerInput = runtime_contract_convert(wire).unwrap();
|
||||
assert_eq!(restored, input);
|
||||
let request = WorkerCompletionsRequest {
|
||||
kind: protocol::CompletionKind::FeatureArgument,
|
||||
prefix: "資料/".into(),
|
||||
context: Some(protocol::CompletionContext {
|
||||
invocation: protocol::FeatureInvocationIdentity("builtin:test/prepare".into()),
|
||||
argument: Some("path".into()),
|
||||
}),
|
||||
request_id: Some("completion-nonce".into()),
|
||||
};
|
||||
let wire: runtime_api::CompletionRequest =
|
||||
runtime_contract_convert(request.clone()).unwrap();
|
||||
let restored: WorkerCompletionsRequest = runtime_contract_convert(wire).unwrap();
|
||||
assert_eq!(restored, request);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remote_profile_source_uses_workspace_config_archive_reference() {
|
||||
let request = embedded_spawn_request();
|
||||
|
||||
@@ -6508,23 +6508,11 @@ fn worker_input_request_from_api(
|
||||
)));
|
||||
}
|
||||
};
|
||||
let segments = request
|
||||
.segments
|
||||
.map(|segments| {
|
||||
segments
|
||||
.into_iter()
|
||||
.map(|segment| {
|
||||
serde_json::from_value::<Segment>(segment)
|
||||
.map_err(|error| invalid_contract_value("Worker input segment", error))
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()
|
||||
})
|
||||
.transpose()?;
|
||||
Ok(WorkerInputRequest {
|
||||
kind,
|
||||
content: request.content,
|
||||
submission_request_id: None,
|
||||
segments,
|
||||
segments: request.segments,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6543,9 +6531,10 @@ fn worker_completions_request_from_api(
|
||||
request: server_api::RuntimeWorkerCompletionsRequest,
|
||||
) -> Result<WorkerCompletionsRequest> {
|
||||
Ok(WorkerCompletionsRequest {
|
||||
kind: serde_json::from_value(request.kind)
|
||||
.map_err(|error| invalid_contract_value("Worker completion kind", error))?,
|
||||
kind: request.kind,
|
||||
prefix: request.prefix,
|
||||
context: request.context,
|
||||
request_id: request.request_id,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6641,17 +6630,11 @@ fn worker_completions_result_to_api(
|
||||
Ok(server_api::RuntimeWorkerCompletionsResult {
|
||||
runtime_id: result.worker.runtime_id,
|
||||
worker_id: result.worker.worker_id,
|
||||
kind: serde_json::to_value(result.kind)
|
||||
.map_err(|error| invalid_contract_value("Worker completion kind", error))?,
|
||||
kind: result.kind,
|
||||
prefix: result.prefix,
|
||||
entries: result
|
||||
.entries
|
||||
.into_iter()
|
||||
.map(|entry| {
|
||||
serde_json::to_value(entry)
|
||||
.map_err(|error| invalid_contract_value("Worker completion entry", error))
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?,
|
||||
context: result.context,
|
||||
request_id: result.request_id,
|
||||
entries: result.entries,
|
||||
diagnostics: result.diagnostics.into_iter().map(Into::into).collect(),
|
||||
})
|
||||
}
|
||||
@@ -36263,6 +36246,33 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn feature_completion_api_conversions_preserve_nonce_and_context_for_aba_requests() {
|
||||
for nonce in ["first", "second", "first"] {
|
||||
let json = serde_json::json!({"kind":"feature_argument", "prefix":"資料/", "request_id":nonce,
|
||||
"context":{"invocation":"builtin:test/prepare", "argument":"path"}});
|
||||
let wire: server_api::RuntimeWorkerCompletionsRequest =
|
||||
serde_json::from_value(json.clone()).unwrap();
|
||||
let request = worker_completions_request_from_api(wire).unwrap();
|
||||
assert_eq!(serde_json::to_value(&request).unwrap(), json);
|
||||
let result = worker_completions_result_to_api(WorkerCompletionsResult {
|
||||
worker: RuntimeWorkerRef::new("runtime", "worker"),
|
||||
kind: request.kind,
|
||||
prefix: request.prefix,
|
||||
context: request.context,
|
||||
request_id: request.request_id,
|
||||
entries: Vec::new(),
|
||||
diagnostics: Vec::new(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(result.request_id.as_deref(), Some(nonce));
|
||||
assert_eq!(
|
||||
serde_json::to_value(result.context).unwrap(),
|
||||
json["context"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flow_or_generic_worker_state_change_is_not_ticket_completion_authority() {
|
||||
let change = || {
|
||||
@@ -57327,6 +57337,8 @@ mod tests {
|
||||
serde_json::to_string(&protocol::Method::ListCompletions {
|
||||
kind: protocol::CompletionKind::File,
|
||||
prefix: String::new(),
|
||||
request_id: None,
|
||||
context: None,
|
||||
})
|
||||
.unwrap()
|
||||
.into(),
|
||||
@@ -57807,6 +57819,8 @@ mod tests {
|
||||
method: protocol::Method::ListCompletions {
|
||||
kind: protocol::CompletionKind::File,
|
||||
prefix: String::new(),
|
||||
request_id: None,
|
||||
context: None,
|
||||
},
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user