Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions scripts/orbit-slice1-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1475,11 +1475,21 @@ let firstCredentialToken = '';
currentVersion: 2,
currentEtag: nextEtag,
});
sponsoredAgentEtag = nextEtag;

const clearedRole = await patchJson('/v1/agent/profile', {
role: ' ',
}, { authorization: `Bearer ${firstCredentialToken}`, 'if-match': nextEtag }, NOW + 50);
assert.equal(clearedRole.status, 200, await clearedRole.clone().text());
const clearedRoleBody = await clearedRole.json() as { agent: { role: string; version: number } };
assert.equal(clearedRoleBody.agent.role, '');
assert.equal(clearedRoleBody.agent.version, 3);
const clearedRoleEtag = clearedRole.headers.get('etag') ?? '';
assert.match(clearedRoleEtag, /^"agent-.+-v3"$/u);
sponsoredAgentEtag = clearedRoleEtag;

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

Expand Down Expand Up @@ -1722,6 +1732,23 @@ let firstCredentialToken = '';
};
assert.equal(staleBody.error.code, 'version_conflict');
assert.equal(staleBody.error.details?.conflict?.currentEtag, updatedBody.etag);

const clearedRole = await postJson(
`/v1/mcp/grants/${encodeURIComponent(onboardingGrantId)}/agent/profile/update`,
{ etag: updatedBody.etag, role: ' ' },
serviceHeaders,
NOW + 69,
);
assert.equal(clearedRole.status, 200, await clearedRole.clone().text());
const clearedRoleBody = await clearedRole.json() as {
etag: string;
profile: { bio: string; role: string; accent: string; pinnedRecordId: string | null };
};
assert.notEqual(clearedRoleBody.etag, updatedBody.etag);
assert.equal(clearedRoleBody.profile.role, '');
assert.equal(clearedRoleBody.profile.bio, 'MCP profile update test.');
assert.equal(clearedRoleBody.profile.accent, '#12abef');
assert.equal(clearedRoleBody.profile.pinnedRecordId, null);
});

test('only platform owner can apply all three publication policies', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/data/agentApiContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ export const agentApiContract = {
additionalProperties: false,
properties: {
bio: { type: 'string', minLength: 1, maxLength: 500 },
role: { type: 'string', minLength: 1, maxLength: 80 },
role: { type: 'string', maxLength: 80 },
accent: { type: 'string', pattern: '^#[0-9a-fA-F]{6}$' },
pinnedRecordId: { oneOf: [{ $ref: '#/components/schemas/Uuid' }, { type: 'null' }] },
},
Expand Down
4 changes: 2 additions & 2 deletions src/server/http/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ async function handlePatchOwnAgent(
throw versionConflictError(current, now);
}
const bio = body.bio === undefined ? current.bio : requiredString(body.bio, 'bio', 500);
const role = body.role === undefined ? current.role : requiredString(body.role, 'role', 80);
const role = body.role === undefined ? current.role : requiredString(body.role, 'role', 80, true);
let accent = current.accent;
if (body.accent !== undefined) {
if (typeof body.accent !== 'string' || !/^#[0-9a-f]{6}$/iu.test(body.accent.trim())) {
Expand Down Expand Up @@ -3963,7 +3963,7 @@ export async function handleApiRequest(
throw mcpProfileVersionConflictError(resolved.agent, now);
}
const bio = body.bio === undefined ? resolved.agent.bio : requiredString(body.bio, 'bio', 500);
const role = body.role === undefined ? resolved.agent.role : requiredString(body.role, 'role', 80);
const role = body.role === undefined ? resolved.agent.role : requiredString(body.role, 'role', 80, true);
let accent = resolved.agent.accent;
if (body.accent !== undefined) {
if (typeof body.accent !== 'string' || !/^#[0-9a-f]{6}$/iu.test(body.accent.trim())) {
Expand Down