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
13 changes: 13 additions & 0 deletions src/adversary/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ export function adversaryCoordinatorKey(
return `${input.repositoryId}:${input.pullNumber}`;
}

export function adversarySandboxId(
team: 'blue' | 'purple' | 'publisher',
input: Pick<
AdversaryWorkflowParams,
'repositoryId' | 'pullNumber' | 'deliveryId'
>,
): string {
const delivery = input.deliveryId.toLowerCase().replace(/[^a-z0-9-]/g, '-');
return `adversary-${team}-${input.repositoryId}-${input.pullNumber}-${delivery}`
.slice(0, 63)
.replace(/-+$/, '');
}

export function blueQualifies(result: PurpleTeamResult): boolean {
return Object.values(result.qualification).every(Boolean);
}
Expand Down
8 changes: 1 addition & 7 deletions src/adversary/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
type AdversaryWorkflowOutcome,
type AdversaryWorkflowParams,
adversaryCoordinatorKey,
adversarySandboxId,
adversaryWorkflowParamsSchema,
type BlueTeamInput,
type BlueTeamResult,
Expand Down Expand Up @@ -421,13 +422,6 @@ export class AdversaryWorkflow extends WorkflowEntrypoint<
}
}

function adversarySandboxId(
team: 'blue' | 'purple' | 'publisher',
params: AdversaryWorkflowParams,
): string {
return `adversary-${team}-${params.repositoryId}-${params.pullNumber}-${params.deliveryId}`;
}

async function destroyInStep(
step: WorkflowStep,
team: string,
Expand Down
15 changes: 15 additions & 0 deletions tests/adversary-contracts.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import {
adversaryBranchName,
adversarySandboxId,
blueQualifies,
type PurpleTeamResult,
} from '../src/adversary/contracts.ts';
Expand Down Expand Up @@ -41,4 +42,18 @@ describe('adversary contracts', () => {
'factory/adversary/pr-42-aaaaaaaaaaaa',
);
});

it('builds bounded DNS-label-safe sandbox ids', () => {
const input = {
repositoryId: 348060227,
pullNumber: 17736,
deliveryId: '560CE130_B10A 11F1/862F/F478BF7BDFDE',
};

for (const team of ['blue', 'purple', 'publisher'] as const) {
const id = adversarySandboxId(team, input);
expect(id.length).toBeLessThanOrEqual(63);
expect(id).toMatch(/^[a-z0-9][a-z0-9-]*[a-z0-9]$/);
}
});
});
Loading