scripts/resolve-review-thread.test.mjs
scripts/resolve-review-thread.test.mjsBrowse 7 files
807 tokens
3,147 bytes
Token encoding: o200k_base
Snapshot fac8604
← Back to SKILL.md
1import assert from 'node:assert/strict';2import { spawnSync } from 'node:child_process';3import { chmod, mkdtemp, writeFile } from 'node:fs/promises';4import { tmpdir } from 'node:os';5import { delimiter, dirname, join, resolve } from 'node:path';6import test from 'node:test';7import { fileURLToPath } from 'node:url';8 9const scriptPath = resolve(dirname(fileURLToPath(import.meta.url)), 'resolve-review-thread.mjs');10 11async function createFakeGh() {12 const directory = await mkdtemp(join(tmpdir(), 'resolve-review-thread-test-'));13 const ghPath = join(directory, 'gh');14 await writeFile(15 ghPath,16 [17 '#!/usr/bin/env node',18 "if (process.argv[2] === '--version') {",19 " process.stdout.write('gh version fake\\n');",20 ' process.exit(0);',21 '}',22 "process.stdout.write(process.env.FAKE_GH_STDOUT ?? '{}');",23 '',24 ].join('\n'),25 'utf8',26 );27 await chmod(ghPath, 0o755);28 return directory;29}30 31async function runResolve(args, fakeStdout) {32 const fakeGhDirectory = await createFakeGh();33 return spawnSync(process.execPath, [scriptPath, ...args], {34 encoding: 'utf8',35 env: {36 ...process.env,37 PATH: `${fakeGhDirectory}${delimiter}${process.env.PATH ?? ''}`,38 FAKE_GH_STDOUT: fakeStdout,39 },40 });41}42 43test('rejects unknown CLI flags', () => {44 const result = spawnSync(process.execPath, [scriptPath, '--bogus'], { encoding: 'utf8' });45 46 assert.equal(result.status, 2);47 assert.match(result.stderr, /unknown flag "--bogus"/);48});49 50test('rejects missing thread id', () => {51 const result = spawnSync(process.execPath, [scriptPath], { encoding: 'utf8' });52 53 assert.equal(result.status, 2);54 assert.match(result.stderr, /--thread-node-id is required/);55});56 57test('reports malformed JSON responses', async () => {58 const result = await runResolve(['--thread-node-id', 'THREAD_1'], 'not json');59 60 assert.equal(result.status, 1);61 assert.match(result.stderr, /failed to parse GraphQL response/);62});63 64test('reports GraphQL errors', async () => {65 const result = await runResolve(66 ['--thread-node-id', 'THREAD_1'],67 JSON.stringify({ errors: [{ message: 'Could not resolve thread' }] }),68 );69 70 assert.equal(result.status, 1);71 assert.match(result.stderr, /Could not resolve thread/);72});73 74test('reports unresolved mutation payloads', async () => {75 const result = await runResolve(76 ['--thread-node-id', 'THREAD_1'],77 JSON.stringify({78 data: {79 resolveReviewThread: {80 thread: { id: 'THREAD_1', isResolved: false },81 },82 },83 }),84 );85 86 assert.equal(result.status, 1);87 assert.match(result.stderr, /thread was not resolved successfully/);88});89 90test('prints resolution payloads', async () => {91 const result = await runResolve(92 ['--thread-node-id', 'THREAD_1'],93 JSON.stringify({94 data: {95 resolveReviewThread: {96 thread: { id: 'THREAD_1', isResolved: true },97 },98 },99 }),100 );101 102 assert.equal(result.status, 0);103 assert.deepEqual(JSON.parse(result.stdout), {104 ok: true,105 threadNodeId: 'THREAD_1',106 resolvedThreadId: 'THREAD_1',107 isResolved: true,108 });109});110