fix(v0.2): freeze HWLAB-AgentRun concept boundary for #792

P0 freezes the concept boundary between HWLAB (business session/workspace) and
AgentRun (tenant/policy/execution):

- HWLAB adapter now always uses DEFAULT_HWLAB_AGENTRUN_PROJECT_ID /
  DEFAULT_HWLAB_AGENTRUN_PROVIDER_ID / DEFAULT_HWLAB_AGENTRUN_BACKEND_PROFILE on
  AgentRun runPayload, regardless of caller options. Business projectId belongs
  in workspaceRef only, not in AgentRun projectId.

- commandPayload.projectId is now always set to the HWLAB-fixed
  DEFAULT_HWLAB_AGENTRUN_PROJECT_ID, never undefined and never derived from
  caller options.

- client agent send --session-id <SES> --conversation-id <CONV> without
  --provider-profile now looks up the explicit session record to inherit
  providerProfile / threadId / conversationId. Mismatched --conversation-id
  against the session record aborts with session_conversation_mismatch
  before dispatching to AgentRun (prevents stale session state from being
  used as a new conversation).

Contract tests added (all 4 passing):
- internal/agent/agentrun-dispatch.test.mjs: HWLAB AgentRun assembly fixes
  tenantId/projectId/providerId/backendProfile regardless of options; command
  payload does not leak business projectId into AgentRun command projectId.
- tools/hwlab-cli/client.test.ts: send --session-id + --conversation-id
  inherits explicit session providerProfile; fails with
  session_conversation_mismatch when the session points at a different
  conversation.

P2 (CLI/trace result segregation) and P3 (state machine convergence) remain
for follow-up. Tracked via #792 comment chain.

Tracked-by: pikasTech/HWLAB#792
This commit is contained in:
Codex
2026-06-04 02:18:34 +08:00
parent b23ba1cb82
commit 19438d6aa4
4 changed files with 253 additions and 24 deletions
+40
View File
@@ -176,3 +176,43 @@ function jsonResponse(body, { status = 200 } = {}) {
text: async () => JSON.stringify(body)
};
}
test("HWLAB AgentRun assembly fixes tenantId/projectId/providerId/backendProfile regardless of options (#792)", () => {
// Even if caller passes contradicting projectId / providerId / backendProfile,
// the assembly must use HWLAB-fixed values to keep AgentRun tenant/policy boundaries
const assembly = createHwlabAgentRunDispatchAssembly({
traceId: "trc_hwlab_agentrun_concept_boundary",
prompt: "concept boundary",
commitId,
unideskMainServerIp: "https://unidesk.example.test",
projectId: "pikasTech/SomeOtherProject",
providerId: "OtherProvider",
backendProfile: "codex"
});
// runPayload is the AgentRun tenant/policy payload
assert.equal(assembly.runPayload.tenantId, "hwlab");
assert.equal(assembly.runPayload.projectId, "pikasTech/HWLAB");
assert.equal(assembly.runPayload.providerId, "G14");
assert.equal(assembly.runPayload.backendProfile, "deepseek");
// workspaceRef is fixed to v0.2 lane
assert.equal(assembly.runPayload.workspaceRef.kind, "git-worktree");
assert.equal(assembly.runPayload.workspaceRef.repo, "http://git-mirror-http.devops-infra.svc.cluster.local/pikasTech/HWLAB.git");
assert.equal(assembly.runPayload.workspaceRef.branch, "v0.2");
// resourceBundleRef.commitId must be the 40-char sha
assert.equal(assembly.runPayload.resourceBundleRef.commitId, commitId);
assert.equal(assembly.runPayload.resourceBundleRef.commitId.length, 40);
});
test("HWLAB AgentRun assembly command payload does not leak business projectId into AgentRun command projectId (#792)", () => {
// Business-side projectId belongs in workspaceRef only, not in AgentRun command.projectId.
const assembly = createHwlabAgentRunDispatchAssembly({
traceId: "trc_hwlab_agentrun_command_project",
prompt: "do not leak business project",
commitId,
unideskMainServerIp: "https://unidesk.example.test"
});
// commandPayload.projectId must equal runPayload.projectId (HWLAB-fixed), NOT any business project
assert.equal(assembly.commandPayload.payload.projectId, assembly.runPayload.projectId);
assert.equal(assembly.commandPayload.payload.projectId, "pikasTech/HWLAB");
assert.equal(assembly.runPayload.projectId, "pikasTech/HWLAB");
});