mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-17 10:25:33 +02:00
fix(pairing): harden re-pair per adversarial review
Adversarial review of the diff found four issues, now fixed: - Validate the requested grant BEFORE the supersede revoke: a reducing re-pair with a bad scope/rate no longer destroys the live session and then fails to mint a replacement (assertValidTokenOptions runs up front). - A re-pair with no live session releases tabs orphaned by an expired incarnation, closing the tab-inheritance gap /pair had (DELETE /token already released unconditionally). - Test the DELETE /token revoked=0/tabs>0 path and the /pair orphaned-tab release at the handler level (HTTP e2e can't, headless owns no tabs). - Test the CLI --client root fast-fail; fix its null-guard (parseFlag returns null when --client is absent). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
6fe3e67736
commit
d86edf1f8f
@@ -373,6 +373,24 @@ describe('pair-agent flow end-to-end (HTTP only, no ngrok)', () => {
|
||||
expect((await statusWith(s)).status).not.toBe(401); // still working
|
||||
});
|
||||
|
||||
test('a reducing re-pair with an INVALID scope 400s and leaves the live session intact', async () => {
|
||||
// Regression: the supersede revoke must run AFTER validation. A scope typo
|
||||
// (--restrict red) on a narrowing re-pair must not destroy the session and
|
||||
// then fail to mint a replacement — the agent would be knocked offline.
|
||||
const { setup_key: k } = await pairAs({ clientId: 'validate-me' });
|
||||
const { body: c } = await connectKey(k);
|
||||
const s = c.token as string;
|
||||
expect((await statusWith(s)).status).not.toBe(401);
|
||||
const resp = await fetch(`${daemon.baseUrl}/pair`, {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${daemon.token}` },
|
||||
body: JSON.stringify({ clientId: 'validate-me', scopes: ['red'] }),
|
||||
});
|
||||
expect(resp.status).toBe(400);
|
||||
expect((await resp.json() as any).error).toContain('red');
|
||||
// The working session survives the validation error (not revoked).
|
||||
expect((await statusWith(s)).status).not.toBe(401);
|
||||
});
|
||||
|
||||
// ─── D3: DELETE /token releases tabs unconditionally; 404 only when empty ─
|
||||
|
||||
test('DELETE /token returns tabs_released and 404 only when nothing to revoke or release', async () => {
|
||||
|
||||
Reference in New Issue
Block a user