fix: report unauthenticated auth state honestly
All checks were successful
labels / labels (pull_request) Successful in 12s
ci / test (pull_request) Successful in 4m0s

This commit is contained in:
codex-bot-andresmgsl 2026-09-04 01:56:14 +00:00
parent ed3f234b8e
commit aedce42c56
2 changed files with 11 additions and 3 deletions

View file

@ -295,6 +295,8 @@ auth
} else { } else {
console.log(`Skipping remote revocation (no password provided). Token ${config.tokenId} stays active on ${config.url}; revoke it from the web UI under Settings > Applications.`); console.log(`Skipping remote revocation (no password provided). Token ${config.tokenId} stays active on ${config.url}; revoke it from the web UI under Settings > Applications.`);
} }
} else if (!config.tokenId && !options.localOnly) {
console.log(`Removing local credentials. Stoke did not create this token and cannot revoke it. The token is still valid on ${config.url}; revoke it from the web UI under Settings > Applications.`);
} }
clearConfig(); clearConfig();
@ -313,8 +315,12 @@ auth
try { try {
const config = loadConfig(); const config = loadConfig();
if (!config || !config.token) { if (!config || !config.token) {
console.log('Not authenticated.'); if (options.json) {
return; console.log('{"authenticated": false}');
} else {
console.log('Not authenticated.');
}
process.exit(1);
} }
const client = ForgejoClient.fromConfig(config); const client = ForgejoClient.fromConfig(config);

View file

@ -54,7 +54,7 @@ test('auth status reports an absent session in text and JSON with a failing stat
const json = run(['auth', 'status', '--json'], { STOKE_CONFIG_FILE: missing }); const json = run(['auth', 'status', '--json'], { STOKE_CONFIG_FILE: missing });
assert.equal(json.status, 1); assert.equal(json.status, 1);
assert.equal(json.stdout, '{"authenticated":false}\n'); assert.equal(json.stdout, '{"authenticated": false}\n');
assert.equal(json.stderr, ''); assert.equal(json.stderr, '');
}); });
@ -78,6 +78,8 @@ test('auth logout identifies a supplied token that remains active without changi
assert.match(logout.stdout, /cannot revoke it/i); assert.match(logout.stdout, /cannot revoke it/i);
assert.match(logout.stdout, /still valid on https:\/\/forge\.test/i); assert.match(logout.stdout, /still valid on https:\/\/forge\.test/i);
assert.match(logout.stdout, /Settings > Applications/); assert.match(logout.stdout, /Settings > Applications/);
assert.doesNotMatch(logout.stdout, /Revoked token/);
assert.doesNotMatch(logout.stdout, /Password for/);
assert.doesNotMatch(logout.stdout, /token-that-must-not-be-printed/); assert.doesNotMatch(logout.stdout, /token-that-must-not-be-printed/);
assert.equal(fs.existsSync(cfg), false); assert.equal(fs.existsSync(cfg), false);