mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-11-07 14:38:23 -10:00
refactor(managed-agent): delete the review-minted dead surface and its duplicate
Closes four open review findings by deletion only; the diff shrinks by 92
lines and no production behavior changes.
- R2-3: both convenience constructors on WebShellSessionCapabilities had
zero call sites. The only construction is the canonical 8-arg call in
ManagedAgentService.webShellSession; the contract test touches the record
through .class for schema naming. The 2-arg overload also took
(tasks, actions) while the record's components run (tasks, artifacts,
actions), so it silently mapped its second argument to `actions`.
- R2-4: isSessionCreator was a one-line wrapper over createdSession with
the two String parameters reversed, leaving two public registry methods
that differ only in argument order on a creator-identity authorization
check. Deleted the wrapper; its single caller in
ManagedAgentStore.requireWorkspaceCreator now calls createdSession with
the declared (tenantId, actorId, sessionId) order. Equivalent by
construction: the wrapper body was that same call.
- R2-5 and R2-6: aRenameFailureThatIsNotABrokerRefusalStillRetiresItsCommand
and permanentNonBrokerRenameFailureRetiresItsCommandRow both pin the same
single branch -- renameSession's catch fall-through to
abandonSessionMutation plus dependencyUnavailable("hosted_harness_unavailable")
-- with the same three assertions. They were distinct while the catch still
classified DaemonHttpException(<500) and IllegalStateException separately;
retiring the row on every answered failure collapsed them. The deleted twin
also stubbed its DaemonHttpException double with a bare mock(), so
getStatusCode() returned 0 rather than the documented 4xx, and its
TransactionTemplate wrapper mirrors no production contract (renameSession
carries no @Transactional). The surviving test uses the shared
boundSession/boundServiceWith helpers, which build the identical
workspaceFilesEnabled configuration and the identical bound Session.
The two imports only that test used are removed, as checkstyle enforces
UnusedImports for this module.
Not compiled or executed here: this host has no mvn and only JDK 1.8. Every
removed member was grepped to zero remaining references across the module,
and no surviving import was left unused. The Java lanes on the pre-push head
52704a9de0 are green and are the verifier.
Co-authored-by: Qwen-Coder <[email protected]>
Patrol-Run: qwen-pr-closeout/jmusjmlf72u
This commit is contained in:
1 parent
3683f11622
commit
8d98903588
4 files changed
+1
-92
No files matched your search
-7
@@ -86,13 +86,6 @@ public final class ApiModels {
|
||||
public record WebShellSessionCapabilities(boolean tasks, boolean artifacts, boolean actions,
|
||||
boolean workspaceTurns, boolean sessionClose, boolean sessionArchive,
|
||||
boolean sessionUnarchive, boolean sessionDelete) {
|
||||
public WebShellSessionCapabilities(boolean tasks, boolean artifacts, boolean actions) {
|
||||
this(tasks, artifacts, actions, false, false, false, false, false);
|
||||
}
|
||||
|
||||
public WebShellSessionCapabilities(boolean tasks, boolean actions) {
|
||||
this(tasks, false, actions, false, false, false, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
|
||||
+1
-1
@@ -663,7 +663,7 @@ public class ManagedAgentStore implements AgentStateStore {
|
||||
if (!workspaces.canRead(session.tenantId(), actorId, session.workspace().getWorkspaceId())) {
|
||||
throw new ApiException(HttpStatus.NOT_FOUND, "session_not_found", "The Session was not found.");
|
||||
}
|
||||
if (!workspaces.isSessionCreator(session.tenantId(), session.sessionId(), actorId)) {
|
||||
if (!workspaces.createdSession(session.tenantId(), actorId, session.sessionId())) {
|
||||
throw new ApiException(HttpStatus.FORBIDDEN, "session_operation_forbidden",
|
||||
"Only the Session creator may manage it.");
|
||||
}
|
||||
|
||||
-4
@@ -49,10 +49,6 @@ public class ManagedWorkspaceRegistry {
|
||||
Integer.class, tenantId, sessionId, tenantId, key).isEmpty();
|
||||
}
|
||||
|
||||
public boolean isSessionCreator(String tenantId, String sessionId, String actorId) {
|
||||
return createdSession(tenantId, actorId, sessionId);
|
||||
}
|
||||
|
||||
public boolean canRead(String tenantId, String actorId,
|
||||
String workspaceId) {
|
||||
if (actorId == null || actorId.isEmpty()) {
|
||||
|
||||
-80
@@ -3,14 +3,12 @@ package com.alibaba.qwen.code.managedagent;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import com.alibaba.qwen.code.daemon.DaemonHttpException;
|
||||
import com.alibaba.qwen.code.managedagent.api.ApiException;
|
||||
import com.alibaba.qwen.code.managedagent.api.ApiModels.CommandAdmission;
|
||||
import com.alibaba.qwen.code.managedagent.api.ApiModels.InputBlock;
|
||||
@@ -776,84 +774,6 @@ class ManagedWorkspaceAdmissionTest {
|
||||
sessionId)).isEqualTo("second");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRenameFailureThatIsNotABrokerRefusalStillRetiresItsCommand() {
|
||||
String tenant = "tenant-" + UUID.randomUUID();
|
||||
register(tenant, "ws-a", "storage-a",
|
||||
WorkspaceExecutionProfile.CONFIG_REF,
|
||||
WorkspaceExecutionProfile.POLICY_REF);
|
||||
grant(tenant, "ws-a", "actor-a", true);
|
||||
String digest = "sha256:" + "a".repeat(64);
|
||||
String sessionId = store.insertWorkspaceSessionCommand(tenant,
|
||||
"actor-a", "create", digest, "qwen-code", null, null,
|
||||
List.of(), null, new WorkspaceSelection("ws-a", "."))
|
||||
.sessionId();
|
||||
ManagedAgentProperties enabled = new ManagedAgentProperties();
|
||||
enabled.getHarness().setWorkspaceFilesEnabled(true);
|
||||
ManagedAgentStore gated = new ManagedAgentStore(jdbc, mapper,
|
||||
Clock.systemUTC(), ignored -> {
|
||||
}, registry, enabled);
|
||||
// A Harness that lost the Session answers the rename with a 4xx,
|
||||
// which the client surfaces as a DaemonHttpException — a permanent
|
||||
// failure, but not a broker refusal.
|
||||
DaemonHttpException lost = mock(DaemonHttpException.class);
|
||||
UnavailableHarnessConnector harness =
|
||||
new UnavailableHarnessConnector() {
|
||||
private int renames;
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorkspaceFilesAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attachment createOrLoad(String tenantId,
|
||||
String sessionId, boolean loadExisting) {
|
||||
return new Attachment("boot");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(String tenantId, String sessionId,
|
||||
String title) {
|
||||
if (renames++ == 0) {
|
||||
throw lost;
|
||||
}
|
||||
}
|
||||
};
|
||||
ManagedAgentService service = new ManagedAgentService(gated,
|
||||
new RequestDigests(), null, harness, registry);
|
||||
TransactionTemplate transaction = new TransactionTemplate(
|
||||
transactionManager);
|
||||
|
||||
transaction.executeWithoutResult(status ->
|
||||
assertThatThrownBy(() -> service.renameSession(tenant,
|
||||
"actor-a", "rename-1", sessionId, "first"))
|
||||
.isInstanceOfSatisfying(ApiException.class, error -> {
|
||||
assertThat(error.getStatus())
|
||||
.isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);
|
||||
assertThat(error.getCode())
|
||||
.isEqualTo("hosted_harness_unavailable");
|
||||
}));
|
||||
// The answered mutation retired its command row too, so a fresh key
|
||||
// is admitted instead of wedging on session_operation_active.
|
||||
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM"
|
||||
+ " managed_agent_command WHERE tenant_id = ?"
|
||||
+ " AND session_id = ? AND command_status = 'PENDING'",
|
||||
Integer.class, tenant, sessionId)).isZero();
|
||||
|
||||
transaction.executeWithoutResult(status -> service.renameSession(
|
||||
tenant, "actor-a", "rename-2", sessionId, "second"));
|
||||
assertThat(jdbc.queryForObject("SELECT title FROM"
|
||||
+ " managed_agent_session WHERE tenant_id = ?"
|
||||
+ " AND session_id = ?", String.class, tenant,
|
||||
sessionId)).isEqualTo("second");
|
||||
}
|
||||
|
||||
@Test
|
||||
void enabledCreationRefusesPolicyDriftAndAnotherTenantsMount() {
|
||||
String tenant = "tenant-" + UUID.randomUUID();
|
||||
|
||||
Reference in new issue
Block a user