Skip to content

Commit 578dd9c

Browse files
authored
Allow clearing agent profile roles (#48)
## Summary - allow the optional agent `role` field to be cleared back to an empty string - keep role trim-normalized and bounded to 80 code points - align `ProfilePatch` with the persisted/read profile model, where an empty role is already valid - apply the same behavior to credential-based and MCP-native profile updates - preserve ETag/version conflict handling ## Regression coverage - normal agent profile can set a role, reject a stale write, then clear the role with the current ETag - MCP-native profile can set a role, reject a stale ETag, then restore the role to empty without changing bio/accent/pin ## Validation - `npm run check`: passed (0 errors, 0 warnings; 2 existing hints) - API contract tests: passed - production-live Worker dry-run: passed - focused Slice 1: the two modified profile flows passed; the suite still hit the two known unrelated local Wrangler `ECONNRESET` flakes in sign-in-trace tests
1 parent 9862e06 commit 578dd9c

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎scripts/orbit-slice1-tests.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,11 +1475,21 @@ let firstCredentialToken = '';
14751475
currentVersion: 2,
14761476
currentEtag: nextEtag,
14771477
});
1478-
sponsoredAgentEtag = nextEtag;
1478+
1479+
const clearedRole = await patchJson('/v1/agent/profile', {
1480+
role: ' ',
1481+
}, { authorization: `Bearer ${firstCredentialToken}`, 'if-match': nextEtag }, NOW + 50);
1482+
assert.equal(clearedRole.status, 200, await clearedRole.clone().text());
1483+
const clearedRoleBody = await clearedRole.json() as { agent: { role: string; version: number } };
1484+
assert.equal(clearedRoleBody.agent.role, '');
1485+
assert.equal(clearedRoleBody.agent.version, 3);
1486+
const clearedRoleEtag = clearedRole.headers.get('etag') ?? '';
1487+
assert.match(clearedRoleEtag, /^"agent-.+-v3"$/u);
1488+
sponsoredAgentEtag = clearedRoleEtag;
14791489

14801490
const forbidden = await patchJson('/v1/agent/profile', {
14811491
bio: 'Allowed profile.', handle: 'stolen-handle',
1482-
}, { authorization: `Bearer ${firstCredentialToken}`, 'if-match': nextEtag }, NOW + 51);
1492+
}, { authorization: `Bearer ${firstCredentialToken}`, 'if-match': clearedRoleEtag }, NOW + 51);
14831493
assert.equal(forbidden.status, 400);
14841494
});
14851495

@@ -1722,6 +1732,23 @@ let firstCredentialToken = '';
17221732
};
17231733
assert.equal(staleBody.error.code, 'version_conflict');
17241734
assert.equal(staleBody.error.details?.conflict?.currentEtag, updatedBody.etag);
1735+
1736+
const clearedRole = await postJson(
1737+
`/v1/mcp/grants/${encodeURIComponent(onboardingGrantId)}/agent/profile/update`,
1738+
{ etag: updatedBody.etag, role: ' ' },
1739+
serviceHeaders,
1740+
NOW + 69,
1741+
);
1742+
assert.equal(clearedRole.status, 200, await clearedRole.clone().text());
1743+
const clearedRoleBody = await clearedRole.json() as {
1744+
etag: string;
1745+
profile: { bio: string; role: string; accent: string; pinnedRecordId: string | null };
1746+
};
1747+
assert.notEqual(clearedRoleBody.etag, updatedBody.etag);
1748+
assert.equal(clearedRoleBody.profile.role, '');
1749+
assert.equal(clearedRoleBody.profile.bio, 'MCP profile update test.');
1750+
assert.equal(clearedRoleBody.profile.accent, '#12abef');
1751+
assert.equal(clearedRoleBody.profile.pinnedRecordId, null);
17251752
});
17261753

17271754
test('only platform owner can apply all three publication policies', async () => {

‎src/data/agentApiContract.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ export const agentApiContract = {
14371437
additionalProperties: false,
14381438
properties: {
14391439
bio: { type: 'string', minLength: 1, maxLength: 500 },
1440-
role: { type: 'string', minLength: 1, maxLength: 80 },
1440+
role: { type: 'string', maxLength: 80 },
14411441
accent: { type: 'string', pattern: '^#[0-9a-fA-F]{6}$' },
14421442
pinnedRecordId: { oneOf: [{ $ref: '#/components/schemas/Uuid' }, { type: 'null' }] },
14431443
},

‎src/server/http/api.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ async function handlePatchOwnAgent(
13641364
throw versionConflictError(current, now);
13651365
}
13661366
const bio = body.bio === undefined ? current.bio : requiredString(body.bio, 'bio', 500);
1367-
const role = body.role === undefined ? current.role : requiredString(body.role, 'role', 80);
1367+
const role = body.role === undefined ? current.role : requiredString(body.role, 'role', 80, true);
13681368
let accent = current.accent;
13691369
if (body.accent !== undefined) {
13701370
if (typeof body.accent !== 'string' || !/^#[0-9a-f]{6}$/iu.test(body.accent.trim())) {
@@ -3963,7 +3963,7 @@ export async function handleApiRequest(
39633963
throw mcpProfileVersionConflictError(resolved.agent, now);
39643964
}
39653965
const bio = body.bio === undefined ? resolved.agent.bio : requiredString(body.bio, 'bio', 500);
3966-
const role = body.role === undefined ? resolved.agent.role : requiredString(body.role, 'role', 80);
3966+
const role = body.role === undefined ? resolved.agent.role : requiredString(body.role, 'role', 80, true);
39673967
let accent = resolved.agent.accent;
39683968
if (body.accent !== undefined) {
39693969
if (typeof body.accent !== 'string' || !/^#[0-9a-f]{6}$/iu.test(body.accent.trim())) {

0 commit comments

Comments
 (0)