Files
shields/core/token-pooling/sql-token-persistence.spec.js
DCjanusandcopilot-swe-agent[bot] bd23e5fce6 [GitHub] Store accepted token scopes (#11915)
* feat(github): store token scopes

Assisted-by: Codex <gpt-5.5>

* perf(github): index token scopes

Assisted-by: Codex <gpt-5.5>

* feat(github): persist accepted token scopes

Assisted-by: Codex <gpt-5.5>

* docs(github): clarify OAuth scope capture

Assisted-by: Codex <gpt-5.5>

* docs(github): shorten OAuth scope note

Assisted-by: Codex <gpt-5.5>

* docs(github): clarify default OAuth scopes

Assisted-by: Codex <gpt-5.5>

* docs(github): link OAuth scope discussion

Assisted-by: Codex <gpt-5.5>

* docs(github): mark OAuth scopes as TODO

Assisted-by: Codex <gpt-5.5>

* fix(token-pool): refresh existing token data

Assisted-by: Codex <gpt-5.5>

* fix(token-pool): avoid duplicate revalidated tokens

Assisted-by: Codex:gpt-5.5

* fix(token-pool): remove revalidated tokens from priority queue

Assisted-by: Codex:gpt-5.5

* fix(token-pool): preserve token metadata on re-add

Assisted-by: Codex:gpt-5.5

* chore(github): defer token scopes index

Assisted-by: Codex:gpt-5.5

* fix(github): trim accepted token scopes

Assisted-by: Codex:gpt-5.5

* chore(github): keep token scopes index

Assisted-by: Codex:gpt-5.5

* docs(token-pool): document metadata update semantics

Assisted-by: Codex:gpt-5.5

* chore(github): store token scopes without index

Assisted-by: Codex:gpt-5.5

* chore: rerun ci

* test(token-pool): use mixed scope persistence fixture

Assisted-by: Codex:gpt-5.5

* fix(token-pool): replace invalid tokens on re-add

Keep stale queue references invalid so they can be removed lazily without rebuilding the priority queue.

Assisted-by: Codex:gpt-5.6-sol

* chore: apply Prettier 3.9 formatting

Assisted-by: Codex:gpt-5.6-sol

* chore: retry CI

Assisted-by: Codex:gpt-5.6-sol

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-07-20 15:31:01 +02:00

51 lines
1.3 KiB
JavaScript

import { expect } from 'chai'
import sinon from 'sinon'
import SqlTokenPersistence from './sql-token-persistence.js'
describe('SQL token persistence unit', function () {
const tableName = 'github_user_tokens'
let pool
let persistence
beforeEach(function () {
pool = { query: sinon.stub() }
persistence = new SqlTokenPersistence({
url: 'postgres://example.test/shields',
table: tableName,
})
})
it('loads token scopes', async function () {
pool.query.resolves({
rows: [
{ token: 'unscoped-token', scopes: null },
{ token: 'scoped-token', scopes: ['read:packages'] },
],
})
const tokens = await persistence.initialize(pool)
expect(tokens).to.deep.equal([
{ token: 'unscoped-token', scopes: null },
{ token: 'scoped-token', scopes: ['read:packages'] },
])
sinon.assert.calledOnceWithExactly(
pool.query,
`SELECT token, scopes FROM ${tableName} ORDER BY RANDOM();`,
)
})
it('saves token scopes', async function () {
pool.query.resolves({ rows: [] })
await persistence.initialize(pool)
await persistence.onTokenAdded('scoped-token', {
scopes: ['read:packages'],
})
const [, params] = pool.query.secondCall.args
expect(params).to.deep.equal(['scoped-token', ['read:packages']])
})
})