Files
WeHub Mirror 6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
WeHub snapshot of cb28d14c6f2c081de7a0d8729a8c816c9adef67a
2026-08-10 11:17:50 +08:00

152 lines
4.7 KiB
TypeScript

/**
* @vitest-environment node
*/
import { describe, expect, it } from 'vitest'
import { createPRReviewTool, createPRReviewV2Tool } from '@/tools/github/create_pr_review'
describe('createPRReviewTool request body', () => {
const commitId = 'a'.repeat(40)
const base = {
owner: 'octo',
repo: 'demo',
pullNumber: 7,
event: 'COMMENT' as const,
apiKey: 'ghp_test',
}
it('includes comments and commit_id when provided', () => {
const body = createPRReviewTool.request.body!({
...base,
body: 'Looks good',
commit_id: commitId,
comments: [{ path: 'src/a.ts', body: 'nit', line: 3, side: 'RIGHT' }],
})
expect(body).toEqual({
event: 'COMMENT',
body: 'Looks good',
commit_id: commitId,
comments: [{ path: 'src/a.ts', body: 'nit', line: 3, side: 'RIGHT' }],
})
})
it('requires commit_id when comments are present', () => {
expect(() =>
createPRReviewTool.request.body!({
...base,
body: 'summary',
comments: [{ path: 'a.ts', body: 'x', line: 1, side: 'RIGHT' }],
})
).toThrow(/commit_id is required/)
})
it('omits comments when none are provided', () => {
const body = createPRReviewTool.request.body!({
...base,
body: 'summary only',
})
expect(body).toEqual({ event: 'COMMENT', body: 'summary only' })
expect(body.comments).toBeUndefined()
})
it.each(['COMMENT', 'REQUEST_CHANGES'] as const)('requires a non-empty body for %s', (event) => {
expect(() => createPRReviewTool.request.body!({ ...base, event, body: ' ' })).toThrow(
/body is required/
)
})
it('rejects invalid coordinates instead of forwarding them to GitHub', () => {
expect(() =>
createPRReviewTool.request.body!({
...base,
body: 'summary',
commit_id: 'abc123',
comments: [{ path: 'a.ts', body: 'x', line: 1.5, side: 'RIGHT' }],
})
).toThrow(/comments is invalid/)
})
it('rejects dynamic invalid events and malformed commit ids at the boundary', () => {
expect(() =>
createPRReviewTool.request.body!({ ...base, event: 'PENDING' as never, body: 'summary' })
).toThrow(/event must be/)
expect(() =>
createPRReviewTool.request.body!({
...base,
body: 'summary',
commit_id: ' ',
comments: [{ path: 'a.ts', body: 'x', line: 1, side: 'RIGHT' }],
})
).toThrow(/commit_id must be a full/)
})
})
describe('createPRReviewV2Tool response', () => {
function reviewPayload(overrides: Record<string, unknown> = {}) {
return {
id: 9,
user: {
login: 'octo',
id: 1,
avatar_url: 'https://avatars.githubusercontent.com/u/1',
html_url: 'https://github.com/octo',
type: 'User',
},
body: 'Review summary',
state: 'COMMENTED',
html_url: 'https://github.com/octo/demo/pull/7#pullrequestreview-9',
pull_request_url: 'https://api.github.com/repos/octo/demo/pulls/7',
commit_id: 'a'.repeat(40),
submitted_at: '2026-07-20T00:00:00Z',
...overrides,
}
}
it('preserves GitHub review nullability without inventing values', async () => {
const payload = reviewPayload({ user: null, commit_id: null, submitted_at: undefined })
const result = await createPRReviewV2Tool.transformResponse!(Response.json(payload))
expect(result).toEqual({
success: true,
output: {
id: 9,
user: null,
body: 'Review summary',
state: 'COMMENTED',
html_url: 'https://github.com/octo/demo/pull/7#pullrequestreview-9',
pull_request_url: 'https://api.github.com/repos/octo/demo/pulls/7',
commit_id: null,
},
})
})
it('rejects malformed successful review payloads', async () => {
await expect(
createPRReviewV2Tool.transformResponse!(Response.json(reviewPayload({ body: null })))
).rejects.toThrow('GitHub review response.body must be a string')
await expect(
createPRReviewV2Tool.transformResponse!(Response.json(reviewPayload({ html_url: '' })))
).rejects.toThrow('GitHub review response.html_url must be a non-empty string')
})
it('surfaces the GitHub error message on a non-ok response', async () => {
const result = await createPRReviewV2Tool.transformResponse!(
Response.json({ message: 'Validation Failed' }, { status: 422 })
)
expect(result.success).toBe(false)
expect(result.error).toBe('Validation Failed')
})
it('falls back to a status-based error when the error body has no message', async () => {
const result = await createPRReviewV2Tool.transformResponse!(
new Response('not json', { status: 500 })
)
expect(result.success).toBe(false)
expect(result.error).toBe('Failed to submit PR review (HTTP 500)')
})
})