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
96 changes: 96 additions & 0 deletions src/commands/auth/token/handler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import assert from 'node:assert/strict';
import { test } from 'vitest';

import { OrfeError } from '../../../../src/errors.js';
import { runCoreCommand, runToolCommand } from '../../../../test/support/command-runtime.js';
import { mockAuthTokenMintRequest } from '../../../../test/auth/fixtures.js';
import { withNock } from '../../../../test/support/http-test.js';

test('runOrfeCore mints an auth token for the resolved caller bot', async () => {
await withNock(async () => {
const api = mockAuthTokenMintRequest({ repo: { owner: 'throw-if-null', name: 'orfe' } });

const result = await runCoreCommand({
command: 'auth token',
input: { repo: 'throw-if-null/orfe' },
});

assert.deepEqual(result, {
ok: true,
command: 'auth token',
repo: 'throw-if-null/orfe',
data: {
bot: 'greg',
app_slug: 'GR3G-BOT',
repo: 'throw-if-null/orfe',
token: 'ghs_123',
expires_at: '2026-04-06T12:00:00Z',
auth_mode: 'github-app',
},
});
assert.equal(api.isDone(), true);
});
});

test('executeOrfeTool resolves auth token from context.agent and returns shared success envelope', async () => {
await withNock(async () => {
const api = mockAuthTokenMintRequest();

const result = await runToolCommand({
input: {
command: 'auth token',
repo: 'throw-if-null/orfe',
},
});

assert.deepEqual(result, {
ok: true,
command: 'auth token',
repo: 'throw-if-null/orfe',
data: {
bot: 'greg',
app_slug: 'GR3G-BOT',
repo: 'throw-if-null/orfe',
token: 'ghs_123',
expires_at: '2026-04-06T12:00:00Z',
auth_mode: 'github-app',
},
});
assert.equal(api.isDone(), true);
});
});

test('runOrfeCore rejects bot override input for auth token', async () => {
await assert.rejects(
runCoreCommand({
command: 'auth token',
input: { bot: 'unknown', repo: 'throw-if-null/orfe' },
}),
(error: unknown) => {
assert(error instanceof OrfeError);
assert.equal(error.code, 'invalid_usage');
assert.equal(error.message, 'Command "auth token" does not accept input field "bot".');
return true;
},
);
});

test('executeOrfeTool rejects bot override input for auth token', async () => {
const result = await runToolCommand({
input: {
command: 'auth token',
bot: 'greg',
repo: 'throw-if-null/orfe',
},
});

assert.deepEqual(result, {
ok: false,
command: 'auth token',
error: {
code: 'invalid_usage',
message: 'Command "auth token" does not accept input field "bot".',
retryable: false,
},
});
});
127 changes: 127 additions & 0 deletions src/commands/issue/comment/handler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import assert from 'node:assert/strict';
import { test } from 'vitest';

import { runCoreCommand, runToolCommand } from '../../../../test/support/command-runtime.js';
import { withNock } from '../../../../test/support/http-test.js';
import { mockIssueCommentRequest } from '../../../../test/issue/fixtures.js';

test('runOrfeCore posts a generic issue comment and returns structured success output', async () => {
await withNock(async () => {
const api = mockIssueCommentRequest({ issueNumber: 14, body: 'Hello from orfe' });

const result = await runCoreCommand({
command: 'issue comment',
input: { issue_number: 14, body: 'Hello from orfe' },
});

assert.deepEqual(result, {
ok: true,
command: 'issue comment',
repo: 'throw-if-null/orfe',
data: {
issue_number: 14,
comment_id: 123456,
html_url: 'https://github.com/throw-if-null/orfe/issues/14#issuecomment-123456',
created: true,
},
});
assert.equal(api.isDone(), true);
});
});

test('executeOrfeTool returns the shared success envelope for issue comment', async () => {
await withNock(async () => {
const api = mockIssueCommentRequest({ issueNumber: 14, body: 'Hello from orfe' });

const result = await runToolCommand({
input: { command: 'issue comment', issue_number: 14, body: 'Hello from orfe' },
});

assert.deepEqual(result, {
ok: true,
command: 'issue comment',
repo: 'throw-if-null/orfe',
data: {
issue_number: 14,
comment_id: 123456,
html_url: 'https://github.com/throw-if-null/orfe/issues/14#issuecomment-123456',
created: true,
},
});
assert.equal(api.isDone(), true);
});
});

test('runOrfeCore maps issue comment not-found responses clearly', async () => {
await withNock(async () => {
const api = mockIssueCommentRequest({
issueNumber: 999,
body: 'Hello from orfe',
issueGetStatus: 404,
issueGetResponseBody: { message: 'Not Found' },
});

await assert.rejects(
runCoreCommand({
command: 'issue comment',
input: { issue_number: 999, body: 'Hello from orfe' },
}),
/Issue #999 was not found\./,
);

assert.equal(api.isDone(), false);
});
});

test('runOrfeCore maps issue comment auth failures clearly', async () => {
await withNock(async () => {
const api = mockIssueCommentRequest({
issueNumber: 14,
body: 'Hello from orfe',
issueGetStatus: 403,
issueGetResponseBody: { message: 'Resource not accessible by integration' },
});

await assert.rejects(
runCoreCommand({
command: 'issue comment',
input: { issue_number: 14, body: 'Hello from orfe' },
}),
/GitHub App authentication failed while commenting on issue #14\./,
);

assert.equal(api.isDone(), false);
});
});

test('runOrfeCore rejects pull request targets for issue comment clearly', async () => {
await withNock(async () => {
const api = mockIssueCommentRequest({
issueNumber: 46,
body: 'Hello from orfe',
issueGetResponseBody: {
number: 46,
title: 'Implement `orfe issue comment`',
body: 'PR body',
state: 'open',
state_reason: null,
labels: [],
assignees: [],
html_url: 'https://github.com/throw-if-null/orfe/pull/46',
pull_request: {
url: 'https://api.github.com/repos/throw-if-null/orfe/pulls/46',
},
},
});

await assert.rejects(
runCoreCommand({
command: 'issue comment',
input: { issue_number: 46, body: 'Hello from orfe' },
}),
/Issue #46 is a pull request\. Use pr comment instead\./,
);

assert.equal(api.isDone(), false);
});
});
Loading