Files
simstudioai--sim/apps/sim/tools/github/list_review_threads.test.ts
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

203 lines
5.8 KiB
TypeScript

/**
* @vitest-environment node
*/
import { describe, expect, it } from 'vitest'
import { listReviewThreadsTool } from '@/tools/github/list_review_threads'
import type { ListReviewThreadsParams } from '@/tools/github/types'
const BASE_PARAMS: ListReviewThreadsParams = {
owner: 'octo',
repo: 'demo',
pullNumber: 7,
apiKey: 'ghp_test',
}
function threadsPayload(overrides: Record<string, unknown> = {}) {
return {
data: {
repository: {
pullRequest: {
reviewThreads: {
totalCount: 1,
pageInfo: { hasNextPage: false, endCursor: null },
nodes: [
{
id: 'PRRT_1',
isResolved: false,
path: 'src/index.ts',
line: 12,
comments: {
totalCount: 1,
nodes: [
{
body: 'This leaks a handle.',
authorAssociation: 'MEMBER',
author: { login: 'greptile', __typename: 'Bot' },
},
],
},
},
],
...overrides,
},
reviews: { nodes: [] },
},
},
},
}
}
function requestBody(params: ListReviewThreadsParams) {
const body = listReviewThreadsTool.request.body!(params) as {
query: string
variables: Record<string, unknown>
}
return body
}
describe('github_list_review_threads', () => {
it('asks for the pull request, page size, and cursor it was given', () => {
const body = requestBody({
...BASE_PARAMS,
threadsPerPage: 25,
commentsPerThread: 10,
cursor: 'CURSOR_1',
})
expect(body.query).toContain('reviewThreads(first: $threads, after: $cursor)')
expect(body.query).toContain('authorAssociation')
expect(body.query).toContain('author { login __typename }')
expect(body.variables).toEqual({
owner: 'octo',
repo: 'demo',
number: 7,
threads: 25,
comments: 10,
cursor: 'CURSOR_1',
})
})
it('defaults both page sizes and sends a null cursor for the first page', () => {
expect(requestBody(BASE_PARAMS).variables).toMatchObject({
threads: 50,
comments: 50,
cursor: null,
})
})
it('rejects a page size GitHub would refuse', () => {
expect(() => requestBody({ ...BASE_PARAMS, threadsPerPage: 101 })).toThrow(
/threadsPerPage must be an integer between 1 and 100/
)
expect(() => requestBody({ ...BASE_PARAMS, commentsPerThread: 0 })).toThrow(
/commentsPerThread must be an integer between 1 and 100/
)
})
it('parses threads, their comments, and the page cursor', async () => {
const result = await listReviewThreadsTool.transformResponse!(
Response.json(threadsPayload({ pageInfo: { hasNextPage: true, endCursor: 'CURSOR_2' } })),
BASE_PARAMS
)
expect(result.success).toBe(true)
expect(result.output).toMatchObject({
totalCount: 1,
hasNextPage: true,
endCursor: 'CURSOR_2',
latestReview: null,
})
expect(result.output.threads).toEqual([
{
id: 'PRRT_1',
isResolved: false,
path: 'src/index.ts',
line: 12,
commentsTotalCount: 1,
comments: [
{
body: 'This leaks a handle.',
authorAssociation: 'MEMBER',
authorLogin: 'greptile',
authorType: 'Bot',
},
],
},
])
})
it('keeps the truncation signal: totalCount can exceed the fetched comments', async () => {
const payload = threadsPayload()
payload.data.repository.pullRequest.reviewThreads.nodes[0].comments.totalCount = 80
const result = await listReviewThreadsTool.transformResponse!(
Response.json(payload),
BASE_PARAMS
)
expect(result.output.threads[0].commentsTotalCount).toBe(80)
expect(result.output.threads[0].comments).toHaveLength(1)
})
it('reads a null line and a deleted comment author as null rather than failing', async () => {
const payload = threadsPayload()
payload.data.repository.pullRequest.reviewThreads.nodes[0].line = null
payload.data.repository.pullRequest.reviewThreads.nodes[0].comments.nodes[0].author = null
const result = await listReviewThreadsTool.transformResponse!(
Response.json(payload),
BASE_PARAMS
)
expect(result.output.threads[0].line).toBeNull()
expect(result.output.threads[0].comments[0]).toMatchObject({
authorLogin: null,
authorType: null,
})
})
it('returns the newest submitted review with its author type', async () => {
const payload = threadsPayload()
payload.data.repository.pullRequest.reviews = {
nodes: [
{
state: 'COMMENTED',
submittedAt: '2026-01-02T00:00:00Z',
author: { login: 'greptile', __typename: 'Bot' },
},
],
}
const result = await listReviewThreadsTool.transformResponse!(
Response.json(payload),
BASE_PARAMS
)
expect(result.output.latestReview).toEqual({
state: 'COMMENTED',
submittedAt: '2026-01-02T00:00:00Z',
authorLogin: 'greptile',
authorType: 'Bot',
})
})
it('fails on a GraphQL error payload delivered with HTTP 200', async () => {
const response = Response.json({
data: { repository: null },
errors: [{ message: 'Resource not accessible by integration' }],
})
await expect(listReviewThreadsTool.transformResponse!(response, BASE_PARAMS)).rejects.toThrow(
/Resource not accessible by integration/
)
})
it('fails rather than reporting zero threads when the pull request is missing', async () => {
const response = Response.json({ data: { repository: { pullRequest: null } } })
await expect(listReviewThreadsTool.transformResponse!(response, BASE_PARAMS)).rejects.toThrow(
/pullRequest was not found/
)
})
})