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
111 changes: 111 additions & 0 deletions .github/workflows/freebuff-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Freebuff E2E Tests

on:
push:
branches: ['main']
pull_request:
branches: ['main']
workflow_dispatch: # Manual trigger

concurrency:
group: freebuff-e2e-${{ github.ref }}
cancel-in-progress: true

jobs:
build-freebuff:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@v6

- uses: ./.github/actions/setup-project

- name: Set environment variables
env:
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
run: |
VAR_NAMES=$(bun scripts/generate-ci-env.ts --scope client)
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
' >> $GITHUB_ENV
echo "FREEBUFF_MODE=true" >> $GITHUB_ENV
echo "NEXT_PUBLIC_CB_ENVIRONMENT=prod" >> $GITHUB_ENV
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV

- name: Build Freebuff binary
run: bun freebuff/cli/build.ts 0.0.0-e2e

- name: Smoke test binary
run: |
chmod +x cli/bin/freebuff
cli/bin/freebuff --version

- name: Upload binary
uses: actions/upload-artifact@v7
with:
name: freebuff-binary
path: cli/bin/freebuff
retention-days: 1

e2e:
needs: build-freebuff
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
test:
- version
- startup
- help-command
- slash-commands
- ads-behavior
- agent-startup
- code-edit
- terminal-command
name: e2e-${{ matrix.test }}
steps:
- name: Checkout repository
uses: actions/checkout@v6

- uses: ./.github/actions/setup-project

- name: Install tmux
run: sudo apt-get update && sudo apt-get install -y tmux

- name: Download Freebuff binary
uses: actions/download-artifact@v4
with:
name: freebuff-binary
path: cli/bin/

- name: Make binary executable
run: chmod +x cli/bin/freebuff

- name: Set environment variables
env:
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
run: |
VAR_NAMES=$(bun scripts/generate-ci-env.ts)
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
' >> $GITHUB_ENV
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
echo "NEXT_PUBLIC_CB_ENVIRONMENT=test" >> $GITHUB_ENV
echo "CODEBUFF_GITHUB_TOKEN=${{ secrets.CODEBUFF_GITHUB_TOKEN }}" >> $GITHUB_ENV
echo "CODEBUFF_API_KEY=${{ secrets.CODEBUFF_API_KEY }}" >> $GITHUB_ENV

- name: Build SDK
run: cd sdk && bun run build

- name: Run e2e test - ${{ matrix.test }}
run: bun test freebuff/e2e/tests/${{ matrix.test }}.e2e.test.ts --timeout=120000

- name: Upload tmux session logs on failure
if: failure()
uses: actions/upload-artifact@v7
with:
name: tmux-logs-${{ matrix.test }}
path: debug/tmux-sessions/
retention-days: 7
2 changes: 1 addition & 1 deletion cli/release/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codebuff",
"version": "1.0.630",
"version": "1.0.631",
"description": "AI coding agent",
"license": "MIT",
"bin": {
Expand Down
1 change: 1 addition & 0 deletions common/src/types/session-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const AgentOutputSchema = z.discriminatedUnion('type', [
type: z.literal('error'),
message: z.string(),
statusCode: z.number().optional(),
error: z.string().optional(),
}),
])
export type AgentOutput = z.infer<typeof AgentOutputSchema>
Expand Down
29 changes: 29 additions & 0 deletions common/src/util/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,35 @@ export function unwrapPromptResult<T>(result: PromptResult<T>): T {
return result.value
}

/**
* Parses a JSON response body string from an API error to extract structured error details.
* Used to extract machine-readable error codes and human-readable messages from API responses
* (e.g., AI SDK's APICallError includes a responseBody with the server's JSON response).
*
* Returns extracted fields, or an empty object if the responseBody is not a valid JSON string
* with the expected shape.
*/
export function parseApiErrorResponseBody(responseBody: unknown): {
errorCode?: string
message?: string
} {
if (typeof responseBody !== 'string') return {}
try {
const parsed: unknown = JSON.parse(responseBody)
if (!parsed || typeof parsed !== 'object') return {}
const result: { errorCode?: string; message?: string } = {}
if ('error' in parsed && typeof (parsed as { error: unknown }).error === 'string') {
result.errorCode = (parsed as { error: string }).error
}
if ('message' in parsed && typeof (parsed as { message: unknown }).message === 'string') {
result.message = (parsed as { message: string }).message
}
return result
} catch {
return {}
}
}

// Extended error properties that various libraries add to Error objects
interface ExtendedErrorProperties {
status?: number
Expand Down
Loading
Loading