| 1 | import { execFile, execFileSync } from 'node:child_process'; |
| 2 | import { mkdtempSync, rmSync |
| 3 | import { tmpdir } |
| 4 | import path from 'node:path |
| 5 | import { promisify } |
| 6 | import type { INestApplication |
| 7 | import request from 'supertest |
| 8 | import { afterAll, beforeAll |
| 9 | |
| 10 | import { type Database, |
| 11 | import { eq } |
| 12 | |
| 13 | import { DATABASE } |
| 14 | import { hasBackends, signUp |
| 15 | |
| 16 | describe.skipIf(!hasBackends |
| 17 | let app: |
| 18 | let origin: |
| 19 | let owner: |
| 20 | let work: |
| 21 | const username = |
| 22 | let repo: |
| 23 | |
| 24 | const api = |
| 25 | const remote = |
| 26 | `${origin.replace( |
| 27 | const git = |
| 28 | execFileSync( |
| 29 | 'git', |
| 30 | ['-c', 'user.name=E2E' |
| 31 | { cwd: work, |
| 32 | ).trim(); |
| 33 | // The server runs in this process, so anything that talks to it must not block the event loop. |
| 34 | const run = |
| 35 | promisify(execFile)('git |
| 36 | cwd: work, |
| 37 | env: { ...process |
| 38 | }); |
| 39 | |
| 40 | beforeAll(async () |
| 41 | ({ app, origin |
| 42 | owner = await |
| 43 | repo = ( |
| 44 | await api() |
| 45 | .post('/api/repositories') |
| 46 | .set('cookie', |
| 47 | .send({ name: |
| 48 | .expect(201) |
| 49 | ).body.slug; |
| 50 | |
| 51 | work = mkdtempSync( |
| 52 | git('init', |
| 53 | git('commit', |
| 54 | git('checkout', |
| 55 | writeFileSync( |
| 56 | path.join(work |
| 57 | 'too big for a 1 byte limit\n', |
| 58 | ); |
| 59 | git('add', |
| 60 | git('commit', |
| 61 | await run('push |
| 62 | }, 120_000); |
| 63 | |
| 64 | afterAll(async () |
| 65 | await app?.close |
| 66 | if (work) rmSync |
| 67 | }); |
| 68 | |
| 69 | it('leaves the refs unwritten and says why on the request', |
| 70 | const { body: |
| 71 | .post(`/api/repositories/${username |
| 72 | .set('cookie', |
| 73 | .send({ title: |
| 74 | .expect(201); |
| 75 | |
| 76 | await vi.waitFor |
| 77 | async () => |
| 78 | const { body |
| 79 | .get(`/api/repositories/${username |
| 80 | .expect(200); |
| 81 | expect(body.pullRefsBlocked |
| 82 | }, |
| 83 | { timeout: 15_000, interval |
| 84 | ); |
| 85 | const { stdout |
| 86 | expect(stdout).toBe |
| 87 | expect( |
| 88 | await app |
| 89 | .get<Database |
| 90 | .select() |
| 91 | .from(schema.pullRequestRefWritePending |
| 92 | .where(eq(schema |
| 93 | ).toEqual([]); |
| 94 | }); |
| 95 | }); |