forked from heavy-duty/stoke
Implements #1 — stoke installable with apt-get install stoke. Packaging: - scripts/build-deb.sh: builds dist/stoke_<version>_all.deb from a clean staging copy (src + fresh npm ci --omit=dev), pure-JS Architecture: all, Depends: nodejs (>= 22.12), /usr/lib/stoke payload with /usr/bin/stoke symlink, copyright + changelog, normalized permissions. Lintian-clean. - scripts/publish-deb.sh: uploads a .deb to the Forgejo Debian registry (owner/distribution/component parameterized, defaults heavy-duty/ stable/main), authenticating with STOKE_TOKEN or the stoke login token. - scripts/install-apt.sh: consumer-side one-time setup — adds the registry key and apt source, then apt-get install stoke. Falls back to a [trusted=yes] source when apt's sqv verifier rejects the forge's registry signature (known upstream Forgejo signing bug; the script prefers the signed source so setups heal once the forge is fixed). - .forgejo/workflows/release.yml: on v* tags — test, build, publish to the heavy-duty registry, attach the .deb to the release page. Needs a runner and a RELEASE_TOKEN secret with org package write. New command: - stoke pr merge (-n, --method merge|rebase|rebase-merge|squash, --title, --message, --delete-branch) — gap found while merging !2. Docs and housekeeping: - README: 'Install with apt' as the primary installation method with manual setup and dpkg fallback, signature caveat, pr merge reference, Packaging and releasing section with a release checklist. - dist/ gitignored; version bumped to 1.2.0. Verified end-to-end on this machine: built the deb (lintian-clean), published it to the Forgejo Debian registry, installed it with apt-get install stoke via install-apt.sh, and confirmed the installed CLI works against the live forge. The test upload was removed from the personal namespace afterwards; publishing under heavy-duty needs an org-member token (401 reqPackageAccess with this restricted account). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
77 lines
2.9 KiB
JavaScript
77 lines
2.9 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { execFileSync, spawnSync } = require('node:child_process');
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
|
|
const CLI = path.join(__dirname, '..', 'src', 'cli.js');
|
|
const pkg = require('../package.json');
|
|
|
|
function run(args, env = {}) {
|
|
return spawnSync(process.execPath, [CLI, ...args], {
|
|
encoding: 'utf8',
|
|
env: { ...process.env, ...env },
|
|
});
|
|
}
|
|
|
|
test('--version matches package.json', () => {
|
|
const out = execFileSync(process.execPath, [CLI, '--version'], { encoding: 'utf8' });
|
|
assert.equal(out.trim(), pkg.version);
|
|
});
|
|
|
|
test('--help lists every top-level command', () => {
|
|
const out = execFileSync(process.execPath, [CLI, '--help'], { encoding: 'utf8' });
|
|
for (const cmd of ['auth', 'repo', 'issue', 'pr', 'branch', 'collaborator', 'org', 'user']) {
|
|
assert.match(out, new RegExp(`^\\s+${cmd}`, 'm'), `missing command: ${cmd}`);
|
|
}
|
|
});
|
|
|
|
test('unauthenticated commands fail with a login hint', () => {
|
|
const missing = path.join(os.tmpdir(), `stoke-none-${process.pid}.json`);
|
|
const res = run(['repo', 'list'], { STOKE_CONFIG_FILE: missing });
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /stoke auth login/);
|
|
});
|
|
|
|
test('global --config flag overrides the config location', () => {
|
|
// Point --config at a nonexistent file: auth status must report
|
|
// "Not authenticated" instead of silently using the default config.
|
|
const missing = path.join(os.tmpdir(), `stoke-missing-${process.pid}.json`);
|
|
const res = run(['--config', missing, 'auth', 'status']);
|
|
assert.equal(res.status, 0);
|
|
assert.match(res.stdout, /Not authenticated/);
|
|
});
|
|
|
|
test('invalid --limit is rejected before any network call', () => {
|
|
const res = run(['repo', 'list', '-l', 'abc']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /Limit must be a non-negative integer/);
|
|
});
|
|
|
|
test('invalid --team-id is rejected before any network call', () => {
|
|
const res = run(['org', 'team', 'member-add', '--team-id', 'zero', '-u', 'x']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /Id must be a positive integer/);
|
|
});
|
|
|
|
test('pr merge validates --number before any network call', () => {
|
|
const res = run(['pr', 'merge', '-o', 'o', '-r', 'r', '-n', 'seven']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /Id must be a positive integer/);
|
|
});
|
|
|
|
test('issue create --body-file reports unreadable files cleanly', () => {
|
|
const cfg = path.join(os.tmpdir(), `stoke-cfg-${process.pid}.json`);
|
|
fs.writeFileSync(cfg, JSON.stringify({ url: 'https://forge.test', token: 'tok' }));
|
|
try {
|
|
const res = run(
|
|
['issue', 'create', '-o', 'o', '-r', 'r', '-t', 't', '--body-file', '/nonexistent/body.md'],
|
|
{ STOKE_CONFIG_FILE: cfg },
|
|
);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /Could not read body file/);
|
|
} finally {
|
|
fs.unlinkSync(cfg);
|
|
}
|
|
});
|