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
5 changes: 5 additions & 0 deletions .changeset/0017-fix-download-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cdot65/prisma-airs-cli": patch
---

Fix `airs redteam prompt-sets download` crashing with `Cannot read properties of undefined (reading 'getToken')`. The previous workaround reached into SDK internals that no longer exist. With `@cdot65/prisma-airs-sdk` 0.8.3 the SDK now returns CSV correctly, so the workaround is removed and the method delegates straight to `customAttacks.downloadTemplate()`.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"license": "MIT",
"dependencies": {
"@anthropic-ai/vertex-sdk": "^0.14.4",
"@cdot65/prisma-airs-sdk": "^0.8.1",
"@cdot65/prisma-airs-sdk": "^0.8.3",
"@inquirer/prompts": "^8.3.0",
"@langchain/anthropic": "^1.3.25",
"@langchain/aws": "^1.3.3",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 1 addition & 20 deletions src/airs/promptsets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,7 @@ export class SdkPromptSetService implements PromptSetService {
}

async downloadTemplate(uuid: string): Promise<string> {
// WORKAROUND: Bypass SDK's downloadTemplate — it routes through managementHttpRequest
// which unconditionally JSON.parse()s the response, but this endpoint returns text/csv.
// Make a raw fetch using the SDK's OAuth client instead.
// Tracked upstream: https://github.com/cdot65/prisma-airs-sdk/issues/77
const internals = this.client.customAttacks as unknown as {
baseUrl: string;
oauthClient: { getToken(): Promise<string> };
};
const token = await internals.oauthClient.getToken();
const base = internals.baseUrl.replace(/\/+$/, '');
const url = `${base}/v1/custom-attack/download-template/${uuid}`;
const res = await fetch(url, {
method: 'GET',
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) {
const body = await res.text();
throw new Error(`Download template failed (${res.status}): ${body}`);
}
return res.text();
return this.client.customAttacks.downloadTemplate(uuid);
}

async uploadPromptsCsv(uuid: string, file: Blob): Promise<{ message: string; status: number }> {
Expand Down
30 changes: 5 additions & 25 deletions tests/unit/airs/promptsets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const mockCreatePropertyValue = vi.fn();
vi.mock('@cdot65/prisma-airs-sdk', () => ({
RedTeamClient: vi.fn().mockImplementation(() => ({
customAttacks: {
baseUrl: 'https://api.example.com',
oauthClient: { getToken: vi.fn().mockResolvedValue('mock-token') },
createPromptSet: mockCreatePromptSet,
createPrompt: mockCreatePrompt,
listPromptSets: mockListPromptSets,
Expand Down Expand Up @@ -261,36 +259,18 @@ describe('SdkPromptSetService', () => {
});

describe('downloadTemplate', () => {
it('returns CSV template string via raw fetch', async () => {
const mockFetch = vi.fn().mockResolvedValue({
ok: true,
text: () => Promise.resolve('prompt,goal\n"test","test goal"'),
});
vi.stubGlobal('fetch', mockFetch);

it('delegates to SDK and returns CSV string', async () => {
mockDownloadTemplate.mockResolvedValue('prompt,goal\n"test","test goal"');
const result = await service.downloadTemplate('ps-1');
expect(result).toBe('prompt,goal\n"test","test goal"');
expect(mockFetch).toHaveBeenCalledWith(
expect.stringContaining('/v1/custom-attack/download-template/ps-1'),
expect.objectContaining({ method: 'GET' }),
);

vi.unstubAllGlobals();
expect(mockDownloadTemplate).toHaveBeenCalledWith('ps-1');
});

it('throws on non-OK response', async () => {
const mockFetch = vi.fn().mockResolvedValue({
ok: false,
status: 404,
text: () => Promise.resolve('Not found'),
});
vi.stubGlobal('fetch', mockFetch);

it('propagates SDK errors', async () => {
mockDownloadTemplate.mockRejectedValue(new Error('Download template failed (404)'));
await expect(service.downloadTemplate('ps-1')).rejects.toThrow(
'Download template failed (404)',
);

vi.unstubAllGlobals();
});
});

Expand Down
Loading